问题
I have a label on my DetailViewController and it's not changing when I try to edit it.
This is how my code currently looks like
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"MySegue"]) {
// Get destination view
DetailViewController *vc = [segue destinationViewController];
NSLog(@"Goes here");
vc.titleLabel.text = @"My new UIlabel";
}
}
回答1:
You could use NSNotification or better in your case use this via NSUserDefaults:
[[NSUserDefaults standardUserDefaults] setObject:@"My Label" forKey:@"detailTitle"];
[[NSUserDefaults standardUserDefaults] synchronise];
and in the viewWillAppear of the Detail you read it:
self.titleLabel.title = [[NSUserDefaults standardUserDefaults] objectForKey:@"detailTitle"];
来源:https://stackoverflow.com/questions/17506591/label-not-changing-with-segue