开发者

Initialize UIPickerView

I want to create a UIPickerView with the easiest way possible, because all of what I know Is not enough to help me

Ok what I ment is that I am trying to get a UISegmented that will end up creating a UIPickerView but I want to create a UIPickerView that shows up when I select one of the segments in the segmented control animated, and also the pickerview is supposed to use an array that has colors like red green blue


Ok what I ment is that I am trying to get a UISegmented that will end up creating a U开发者_如何学JAVAIPickerView but I want to create a UIPickerView that shows up when I select one of the segments in the segmented control animated, and also the pickerview is supposed to use an array that has colors like red green blue


For your UISegmentedControl, you'll need to register target-action methods. For example:

[segmentedControl addTarget:self
                 action:@selector(updatePicker:)
       forControlEvents:UIControlEventValueChanged];

Inside of updatePicker, set a variable that corresponds to whatever you want to show in your picker. Then, to your picker instance (you should only have one instance of this class), send the reloadAllComponents message. This will update the picker by querying the delegate for new data. In your delegate (which can probably all be the same class), you'll want to check the value of the variable you set in updatePicker to determine what data to return to the picker.


This page has video and instructions on how to add UIPickerView programmatically in Swift, i.e. it does not use Interface Builder or Story Board, everything is done in a few lines of code.

http://www.appswiftprogramming.com/pg/2171/UIPickerView_Programmatically

You can add your custom view in the UIPickerView if you want something more advanced. It shows that too.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜