passing data between view controllers in storyboards
-
11-06-2021 - |
Question
there are two view controllers with an embedded navigation controller. the 1st one has a table view. the second one, named "AfterTableViewController" has a label in it.
I wanna be able to set the label, in the prepareForSegue
method which is in the 1st view controller implementation file.
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
AfterTableViewController *afc = (AfterTableViewController*) segue.destinationViewController;
afc.title = @"the title"; // this works
afc.theLabel.text = @"hello"; // this doesn't work
}
how should I set the label?
Solution
Seeing as you are only trying to set the text value of the label, it would be best to create an other NSString property for this UILabel's text in your AfterTableViewController and then use it when constructing theLabel.
OTHER TIPS
You have to make sure to add theLabel
as a (synthesized) property within the AfterTableViewController
for this to work.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow