工作在ViewController
我有以下几点:的UILabel的setText不viewWillAppear中
- (void)viewWillAppear:(BOOL)animated
{
DataObject *theDataObject = [self theAppDataObject];
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateFormat:@"MMM dd, yyyy HH:mm"];
NSString *dateStr = [formatter stringFromDate:theDataObject.deadline];
NSLog(@"Logged dateStr: %@", dateStr);
[dateTimeLabel setText:dateStr];
[super viewWillAppear:animated];
}
澄清:dateTimeLabel
IS在xib
文件接线。该viewWillAppear
方法明确地从另一个ViewController
叫,并发射,像这样:
- (IBAction)setDateTimeButtonClicked:(id)sender
{
DataObject *theDataObject = [self theAppDataObject];
theDataObject.deadline = [datePicker date];
FirstMobileViewController *mobileVC = [[FirstMobileViewController alloc] init];
[mobileVC viewWillAppear:YES];
[mobileVC release];
[UIView transitionWithView:self.view.superview
duration:0.5
options:UIViewAnimationOptionTransitionFlipFromRight | UIViewAnimationOptionLayoutSubviews | UIViewAnimationOptionAllowAnimatedContent
animations:^{[self.view removeFromSuperview];}
completion:NULL];
}
的viewWillAppear
方法烧制 - 在dateStr
由NSLog
适当地记录当上海华再次显示。但dateTimeLabel
从未更新。显然,评论NSLog
系列没有什么区别。
的狂揽的事情是,即使NSLog
日志dateStr
就好了,如果我改变dateStr
,比方说,@"Yo!"
甚至到本地初始化字符串,然后dateTimeLabel
将更新,没有问题。
缺少什么我在这里?
你确定'[super viewWillAppear:animated];'需要在最后被调用,而不是在实现的开始?尝试将调用移动到实现的第一行,看看它是否有所作为。 – dasblinkenlight 2012-03-09 04:22:55
@dasblinkenlight我试着将'super'调用移动到顶端,它没有什么区别。真的,它感觉像是在黑暗中拍摄的,因为字符串文字工作得很好:'[dateTimeLabel setText:@“Woof!”]' – Lockjaw 2012-03-09 04:27:04
我想你一定错过了dateTimeLabel的IBOutlet绑定。检查它的连接? – 2012-03-09 04:31:24