label not changing with Segue [duplicate]

谁都会走 提交于 2019-12-12 00:43:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!