Click here to Skip to main content
15,867,849 members
Articles / Mobile Apps / iOS
Article

Picking my favourite car

Rate me:
Please Sign up or sign in to vote.
1.83/5 (6 votes)
18 Feb 2016CPOL1 min read 11.3K   35   1   1
Using the UIPickerView in iOS

Introduction

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:

Image 1

Background

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. 

Image 2

Finally you need to implement the mandatory delegate functions to bring the UIPickerView to life.

Image 3

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.

History

- 18/2/16 Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Germany Germany
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.

Comments and Discussions

 
GeneralInteresting Category Pin
Bassam Abdul-Baki7-Mar-16 2:43
professionalBassam Abdul-Baki7-Mar-16 2:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.