我在导航控制器上推送一个对象,但是当我从该视图控制器返回控件时,它会使应用程序崩溃。
[self.navigationController pushViewController:chequeDetails animated:YES];
[chequeDetails release];
但是当我用
编写相同的代码时[self.navigationController pushViewController:chequeDetails animated:YES];
chequeDetails=nil;
[chequeDetails release];
应用程序没有崩溃,但是当我从检查详细信息控制器弹出时,会发现轻微的延迟?
答案 0 :(得分:0)
如果您的秒启动代码,则不会释放chequeDetails
,因为在nil对象上调用release
并不是什么:
[self.navigationController pushViewController:chequeDetails animated:YES];
chequeDetails=nil;
// calling the release on nill will do nothing
[chequeDetails release];
通常你可以这样做:
[self.navigationController pushViewController:chequeDetails animated:YES];
[chequeDetails release], chequeDetails = nil;
但是如果您执行了alloc,则只释放chequeDetails
,初始化为:
ChequeDetails *chequeDetails = [[ChequeDetails alloc] initWithNibName:@"ChequeDetails" bundle:nil];
所以完整的代码应该是这样的:
ChequeDetails *chequeDetails = [[ChequeDetails alloc] initWithNibName:@"ChequeDetails" bundle:nil];
[self.navigationController pushViewController:chequeDetails animated:YES];
[chequeDetails release], chequeDetails = nil;
答案 1 :(得分:-1)
我不知道Exat ...但我认为你需要创建你的委托的对象,你需要编写appDelegate.navigationController而不是self.navigationController ......
注意:appDelegate是Delegate的对象。