我用两个ViewControllers编写了简单的基于UINavigationController的应用程序;
在第一个视图控制器中,我有以下代码
-(IBAction)loadSecondView
{
SecondView *secondView = [[SecondView alloc]init];
[secondView setTotal:self.total];
[self.navigationController pushViewController:secondView animated:YES];
[secondView release];
[self.navigationController popViewControllerAnimated:YES];
}在第二个视图中,我有一个以编程方式创建的标签。
.....
[self.playerNameField addTarget:self
action:@selector(textFieldFinished:)
.....
- (IBAction)textFieldFinished:(id)sender
{
[sender resignFirstResponder];
}问题是当我触摸键盘的完成按钮时,我的应用程序崩溃了。
[SecondView performSelector:withObject:]: message sent to deallocated instance 0x522af60我知道问题是什么,但我不明白为什么会发生这种情况。
如果我错了,请纠正我。
SecondView *secondView = [[SecondView alloc]init]; // retain 1
[self.navigationController pushViewController:playersNames animated:YES]; //secondView have retain of 2
[secondView release]; // now secondView should have retain of 1发布于 2012-03-07 17:21:17
为什么你按下然后弹出导航控制器,一旦你按下视图就应该切换,playersName控制器和它的视图应该会出现。
此外,我也不清楚为什么你得到了secondView的实例,但从来没有使用它。推送到navigationController上应该会保留控制器,但似乎SecondView永远不会保留,一旦您使用它,以前的控制器已经释放了它。
发布于 2012-03-07 17:20:00
我不明白:
SecondView *secondView = [[SecondView alloc]init];
[self.navigationController pushViewController:playersNames animated:YES];
[secondView release];您是否正在尝试将secondView添加到导航器中?应该是这样的:
SecondView *secondView = [[SecondView alloc]init];
[self.navigationController pushViewController:secondView animated:YES];
[secondView release];https://stackoverflow.com/questions/9598531
复制相似问题