I want to learn the shiny UIPickerView from UIKit for some selecting tasks. By searching the web I stumbled at nice video on Youtube from Bruce Donnerson which covers these basics and so decided to practice and enhance it and share my knowledge.
The final result looks like this:
UIPickerView is a common control in the Apple universe and making the life easy when to choose from a defined selection set as dates or data sets i.e. cars in my sample app. Such standard controls are supplying Voice Over which helps supported people with problems in using devices.
Using the code
The code is a simple sample for using the UIPickerView with a storyboard and code. For using the UIPickerView you need to add one in your storyboard and dont ferget to set the delegates. Delegation is a fundamental principle in Objective-C, without proper understanding and use your in trouble - and wont find out. As I understand it the delegate is like the message receiver and handler in Windows.
Fine is, that the Interface Builder Xcode supports it well. Here you see that the UIPickerView object has set the delegates (in the upper right corner) and its outlet.
Finally you need to implement the mandatory delegate functions to bring the UIPickerView to life.
Points of Interest
Using the UIPickerView is as easy as using a table view. The MVC-model simplifies the data flow.
A nice goodie is the Array loading via the plist. I know, that I will need it some day.
If anybody doesnt understand Interface Builder or the delegation he/she is lost.
And last but not least: Bruce Donnerson has enhanced his tutorial with a Part 2 on UIPickerViews. It contains a sample with 3 pickers.
- 18/2/16 Initial version
I am living in germany and now living from programming for some Years. In my spare time I like sports as jogging, playing football (soccer) and basketball.
We must take care for our planet, because we and our family has no other. And everybody has to do something for it.