0

I have a simple master/detail tableview. In order to get my selection in the master to the detail view, I use the following code to set a label (lTest) in the detail view.

However, it seems that this code is run before/ on a different view, since it does not return an error, but the value of lTest is not changed (not visible on screen after the segue).

(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"showDetail"]) {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];        
        ViewController *Targetview = segue.destinationViewController;
        Targetview.lTest.text=[NSString stringWithFormat:@"Row %d",indexPath.item];
    }
}

How can I change the label in the other view?

4

1 回答 1

1

您的新控制器在执行之前不会设置任何视图viewDidLoad:。给它一个字符串属性来保存您想要拥有的文本lTest并在 期间存储到该文本,然后在它具有其视图prepareForSegue:的文本中更新标签的文本。ViewController

于 2012-08-25T19:18:42.947 回答