0

假设项目正在使用 ARC。ContentViewController 是 UIPopoverController 的内容

- (IBAction)showPop:(UIButton *)button 
{
    _pressDate = [NSDate date];
    ContentViewController *cvc = [[InfoViewController alloc] initWithNibName:@"ContentViewController" bundle:nil];
    self.popController = [[UIPopoverController alloc] initWithContentViewController:cvc];
    cvc.dateLabel.text = [_pressDate description];
    [self.popController presentPopoverFromRect:button.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}

上面的代码有效,没问题。但我注意到,如果我打电话

cvc.dateLabel.text = [_pressDate description];

self.popController = [[UIPopoverController alloc] initWithContentViewController:cvc];

标签没有得到更新。我只是想了解这是怎么回事?

4

1 回答 1

1

有一个拇指规则,你不应该在 viewDidLoad 运行之前编辑 ViewController 的 UI,因为@Phillip Morris描述的原因.. 而不是cvc.dateLabel.text直接在 viewDidLoad 被触发之前设置,声明一个属性textForDateLabel,然后设置cvc.textForDateLabel = [_pressDate description];。然后在viewDidLoad您的 ContentViewController 中,执行self.dateLabel.text = textForDateLabel;

于 2012-11-03T14:02:09.570 回答