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!

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



Hey All!

So I am playing around with UIPickerView. So far I have taught myself how to populate the PickerView using items in an NSArray, and have setup the number of components, rows, title etc. I run the application and the picker view appears, with my array objects. Brilliant! (I was quite pleased with myself at that point haha)

I then setup a second view, and put a button on the first view with the PickerView and added a segue between these two views. So at this stage the user can select an item in the picker view and click the next button which opens up the second view.

What I want to do now, is on the second view, display the title selected in the picker view on the previous view in a label.

I have managed to successfully pass data from an ordinary text field from one view to another, but I can't for the life of me do it for the selection in the picker view.

If anyone can help me I would be so grateful! I think google is getting sick of me asking!

Thank You!!!!

3 Answers

Stone Preston
Stone Preston
42,016 Points

looking at the class reference you might be able to use the selectedRowInComponent method to index your array

row = [repeatPickerView selectedRowInComponent:0];
NSString *selectedItem = [repeatPickerData objectAtIndex:row];

you could add that in prepareForSegue and pass the selectedString to the destinationView controller just like you would with anything else


  • (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ if ([segue.identifier isEqualToString:@"continue"]) { SecondViewController *controller = (SecondViewController *)segue.destinationViewController; controller.textContent = [detailsNames objectAtIndex:[self.pickerView selectedRowInComponent:0]]; }


Thank You!!!

Hey Again Stone Preston ,

Could you point me in the right direction of how to display 'formatted text' e.g: text with paragraphs etc.

Currently depending on the label in the second view (Which comes from picker view title in first view) I am using 'if' statements to display another string in a label below it. However I have a decent amount of content to go here (about 2-3 paragraphs) for each if statement. How can I format this so it looks pretty and not just one long string?

Many thanks! Hope that makes sense.

Stone Preston
Stone Preston
42,016 Points

you can use attributed strings. Treehouse has a workshop you can see here and here is the class reference