Search code examples
objective-cuipickerview

UIPickerview passing text to label in another view


I just started learning so take it easy on me...

The goal is to take the text value of the selected row in the picker and display that in a label in another view.

Right now I'm having difficulty storing the string value, everything compiles and loads but the label in the second view remains blank. De-noobify me please.

//String taken from selected pickerview line and stored in selectedstring
NSString *string = [NSString stringWithFormat:@"You Selected: %@",[_platforms objectAtIndex:row]];
Selectedstring.text = string;

On "next view" button press:

- (IBAction)NextView:(id)sender {
SecondView *secondview = [[SecondView alloc]init];

self.SecondViewData = secondview;
SecondViewData.passedValue = Selectedstring.text;

[self presentViewController:secondview animated:YES completion:nil];

And then in the "viewdidload" area of the next view I have:

label.text = passedValue;

Solution

  • you just need to write below statement in ViewWillAppear instead of viewDidLoad.

    label.text = passedValue;

    thanks