将我的视图控制器两次推送到导航控制器并模拟内存警告,导致应用程序崩溃并出现错误:“消息已发送到解除分配的实例”
我按下按钮按下视图控制器:
-(void)buttonPressed
{
MyViewCOntroller *vc = [[MyViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
情景:
[self buttonPressed];
[self buttonPressed];
如果只推一次就不会发生崩溃。
我也尝试将“vc”移动到父控制器的ivar,但效果是一样的......
也许这会有所帮助,但我正在使用自定义后退按钮及其选择器:
-(void)backButtonPressed
{
[self.navigationController popViewControllerAnimated:YES];
}
答案 0 :(得分:0)
将此vc对象创建为类成员并检查是否存在崩溃
@interface ParentViewController()
{
MyViewCOntroller *vc;
}
@end
@implementation PaintingViewController
-(void)buttonPressed
{
vc = [[MyViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
答案 1 :(得分:0)
找到了解决方案。请参阅我对其他问题的回答:
[UINavigationController retain]: message sent to deallocated instance