开发者

initialize UISegmentedControl programmatically on a view controller with a XIB

I have a UIViewController that has a XIB. I don't want to get rid of the XIB and do everything programmatically for this view, but, the view controller does have a UISegmentedControl element that I would like to in开发者_JAVA技巧itialize and populate programmatically.

Is this possible, and if so, what method on UIViewController is the best choice to do such initialization? Is there any way to tell interface builder that my UISegmentedControl will be initialized programmatically, and don't worry about how many segments it has and whatever else?


Go ahead and create an IBOutlet property in your view controller for the segmented control and then hook it up to the control you create in Interface Builder (may as well create an IBAction method as well for responding to changes in the control). Leave Interface Builder's control defaults to whatever they are, it doesn't matter because you'll be changing them before the control is displayed.

Then in the ViewDidLoad method of your UIViewController you can assign all of the segmented control's properties, including the number of segments, etc.


Just set up the segmented control in the xib in a basic state. Then set it up however you would like in viewDidLoad:

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜