Using a UIPickerView as input for another control

August 30, 2019 · 1 min read

The Problem

You want to offer a pre-selected list of options to a user. This helps protect the content that gets entered into another control like a label or a text field or maybe even just an entry to be stored in a database.

The Solution

So the solution is actually very straight forward, give them a picker that they can scroll to find the desired selection in. As that value changes, you can take that selection and put it somewhere else in your application. In this example, we change the value of a label.

The Steps

  1. Place the UIPickerView and Label on the storyboard.
  2. Make the view controller the delegate and data source for the UIPickerView.
  3. Add the needed protocols for acting as a delegate.
  4. Add an outlet for the label so we can access it’s value in code.
  5. Provide data to the UIPickerView.
  6. Make use of the pickerView:didSelectRow:inComponent: to detect changes and update the label.

The Video




Peter Witham
Peter Witham

Web and Mobile Software Maker, Photographer and Podcaster. I live and breath creativity.
I'd love for you to connect with me via Twitter or if you are a photo person like myself, Instagram.



Related Reads
Podcast: Season 1 Episode 8

All the new hardware announcements from Apple.Apple Watch Series 57th Generation iPadiPhone 11 and M...


September 10, 2019 · 1 min read

Related Reads
Podcast: Season 1 Episode 7

This week, Apple sent out invitations to the September event, as usual we expect it to be iPhones an...


September 02, 2019 · 1 min read

Related Reads
Using a UIPickerView as input for another control

The ProblemYou want to offer a pre-selected list of options to a user. This helps protect the conten...


August 30, 2019 · 1 min read

Related Reads
Podcast: Season 1 Episode 6

In this episode I talk about the state of the beta releases for the platforms and the developer tool...


August 25, 2019 · 1 min read

Related Reads
Podcast: Season 1 Episode 5

Swift Package Manager Grows Up?Xcode 11 will give us integration with the Swift Package Manager. Jus...


July 31, 2019 · 1 min read

Related Reads
Podcast: Season 1 Episode 4

I spent some time with SwiftUI.SwiftUI is the new layout kid on the block, let’s take a look and see...


July 31, 2019 · 1 min read

Related Reads
Podcast: Season 1 Episode 3

App Store Connect and TestFlight get an overhaulIn this episode we take a look at the changes announ...


July 31, 2019 · 3 min read

Related Reads
Podcast: Season 1 Episode 2

Xcode 11 has a lot to offerAll the new changes and features coming to Xcode 11, well the more obviou...


July 31, 2019 · 1 min read

Related Reads
Podcast: Season 1 Episode 1

Welcome to the Podcast / WWDC19It finally happened, it took me a while to get enough courage togethe...


July 30, 2019 · 2 min read

Related Reads
Introduction

Back when Apple announced the Swift programming language at WWDC 2014, I immediately started learnin...


July 05, 2019 · 2 min read