I got stuck about the above while creating the iOS App, so I will record it as a memorandum.
After setting "UISegmentedController" on the storyboard Describe the following sources in the target class.
ViewController.swift
@IBOutlet weak var test: UISegmentedControl!
//Specify the table created in RealmDB
let results = realm.objects(testTable.self)
//Specify table name
let Test = testTable()
//"UISegmentedControl"Select the item in"selectedIndex"Store in
//In this case 0 if First is selected,1 is when Second is selected"selectedIndex"Stored in
let selectedIndex = test.selectedSegmentIndex
//Register with Realm object
try! realm.write {
Test.aaa = test.titleForSegment(at: selectedIndex)!
}
ViewController.swift
@IBOutlet weak var test: UISegmentedControl!
//Specify the acquisition data destination
let results = realm.objects(testTable.self).filter("Id == 1").first
if results?.aaa == "First" {
test.selectedSegmentIndex = 0
}else if results?.aaa == "Second" {
test.selectedSegmentIndex = 1
}
Recommended Posts