【发布时间】:2011-07-11 08:59:52
【问题描述】:
在 UIViewController 类中,我有一个 tableView,它通过单击导航栏按钮被这样调用:
-(IBAction) addButtonPressed:(id)sender {
CreateQuestionController *createQuestionViewController = [[CreateQuestionController alloc] initWithNibName:@"CreateQuestionController" bundle:nil];
[self.navigationController pushViewController:createQuestionViewController animated:YES];
[createQuestionViewController release];
}
这个方法在我的代码中没有其他地方被调用。好吧,当我单击此导航栏按钮并显示视图时,我发现 ViewDidLoad 方法被调用了两次(在这种情况下是正常的)但是我在此处输入的数据丢失了。这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
textView.text=@"Type your question here";
NSLog(@"Question text:%@", textView.text);
}
日志:
2011-07-11 10:56:35.727 HelpMe[1343:207] Question text:Type your question here
2011-07-11 10:56:35.728 HelpMe[1343:207] Question text:(null)
发生了什么事? 谢谢
编辑: 其他症状: - 无法推送另一个视图 - 无法更改按钮的图像
【问题讨论】:
-
没有内存警告,我在里面加了一个NSLog - (void)didReceiveMemoryWarning
-
我建议设置一个断点来查看第二个调用的来源。
-
您是否设置了视图控制器的视图属性。
-
@dasdom:我确实设置了 View 属性。 @omz:我试图在 ViewDidLoad 中放置一个断点,但无法弄清楚第二次调用它的原因。第一次调用它,好的,然后是一堆汇编命令,它再次执行 ViewDidLoad。我是不是在错误的地方设置了断点?
-
您是否覆盖了
CreateQuestionController中的initWithNibName:方法?如果是的话,你能发布代码吗?
标签: iphone cocoa-touch uitableview uiviewcontroller