工作在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