Kevin Kevin - 2 months ago 5
Swift Question

Swift IBoutlet default value

I have set an IBOutlet function for a segmented control. It will display a value only when a user changes the value, but I am wondering how would I be able to display the default value if the user does not select a different option.

For example, a segmented control with [First, Second, Third] would print Second when the user selects Second, but would not print First until the user selects something else and THEN First.

Very simple answer I'm sure, but I am new to Swift so please excuse me.


In your UIViewController viewDidLoad method you should be able to display the default value of the segmented control:

override func viewDidLoad() {
   myLabel?.text = segment.titleForSegmentAtIndex(segment.selectedSegmentIndex)