Is there a way to set the starting selected segment in a UISegmentedControl in Interface Builder, or do I have to do it in the code? If it's in the code, is viewDidLoad the best place to set it?
+1
A:
In Interface Builder when you select UISegmentedControl object on your UI, then in attributes pane, in segment control there's segment drop down menu, select segment that you want selected (0,1 and so on) and tick the 'selected' option below it.
stefanB
2009-06-22 14:21:59
+4
A:
From code, you can just do self.segmentedControl.selectedSegmentIndex = someDefaultIndex
.
Whether you should set it in viewDidLoad:
or not depends entirely on the structure of your application. For example, if your app is starting up and loading the view for the first time and needs to set the control to whatever value it had during the previous run of the app, then it definitely makes sense to do it there.
drewh
2009-06-22 15:10:59