UILabel not updating

后端 未结 5 1212
太阳男子
太阳男子 2021-01-02 10:38

Sorry the basic question, but this bugs me for a while now.

I create a details view from a UITable and try to dynamically set its labels, but they are not updating:

5条回答
  •  南方客
    南方客 (楼主)
    2021-01-02 11:18

    That's because the controller's view is lazily created only when accessed. Pushing the controller accesses the view.

    Alternatively, if you add a line to access the view property, it will work too:

      myViewController *tmpVC = [[myViewController alloc] initWithNibName:@"NIBfile" bundle:nil];
      tmpVC.view;   // Force view creation
      [tmpVC.myLabel setText:tmpObj.myTitle];   // The debugger shows the text: myTitle = "myText"
      NSLog(@"%@", tmpVC.myLabel);              // NSLog will display "myText"
      [self.navigationController pushViewController:tmpVC animated:YES];
    

提交回复
热议问题