Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Tom Coomer
1,331 PointsAdd two UIPickerViews
I would like to have two UIPickerViews in one view. How do I do this? (I am using Swift)
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerData.count
}
//MARK: Delegates
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
return pickerData[row]
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
myLabel.text = pickerData[row]
}
2 Answers
Matthew Reed
Courses Plus Student 17,986 PointsI'm not very experienced with swift but in objective-c you can just compare the picker view passed into the delegate with the other pickers using an if statement.
Stephen Whitfield
16,771 PointsMaybe you could set the frame to one picker to be above that of the other picker. Create a function that evokes both pickers and see what happens.