I have a method on my 2nd View Controller that sets a label's text from a value from the 1st View Controller. How can I call the method on prepareForSegue? I have set my method on the 2nd VC as -(void)setName:(NSString *)name;
Then I call it in the prepareForSegue as [secondVC setName:@"Steve Jobs"];
but the label doesn't seem to change its text, though I can see the value when I NSLog the name variable.
You're trying to set the text on a label that hasn't been loaded yet because prepareForSeque
happens before viewDidLoad
.
One solution is to set the text on a property of the second VC in prepareForSegue
and then configure the label with that text in viewDidLoad
.