我有基于导航的应用程序。我已经创建了应用一个UINavigationController
didFinishLaunchingWithOptions
委托方法是这样的:导航栏后退按钮,崩溃的应用程序
self.initialviewcontroller = [[InitialViewController alloc] initWithNibName:@"InitialViewController" bundle:nil];
UINavigationController *myNavController = [[UINavigationController alloc] initWithRootViewController:self.initialviewcontroller];
self.window.rootViewController = myNavController;
[self.window makeKeyAndVisible];
在InitialViewController
我有一个按钮,其将导航到SecondViewController
。因此,在按钮的动作我推SecondViewController
如下:
if(self.secondView != nil)
self.secondView = nil;
self.secondView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[self.navigationController pushViewController:self.secondView animated:YES];
现状:导航工作正常,我能够InitialViewController
之间导航到SecondViewController
。当我在SecondViewController
并按下设备的主页按钮时,应用程序进入后台,当我重新打开应用程序时,它会从关闭它的位置打开应用程序(即SecondViewController)。现在,如果我按下后退按钮转到InitialViewController,该应用程序崩溃。
它在ios模拟器中工作正常,但设备上发生崩溃。
我不明白我所做的错误是什么?
这里是我的错误代码
异常类型:EXC_BAD_ACCESS(SIGSEGV) 异常代码:KERN_INVALID_ADDRESS在0x654b495d 坠毁主题:0
主题0名:调度队列:com.apple.main线程
发送给我们错误的文本。 –
另外,当你的笔尖与你的视图控制器名称相同时,你可以使用'[[SecondViewController alloc] init];'它将默认为同名的笔尖。 –
我认为问题是,当应用程序在后台输入系统正在释放'InitialViewController'实例,以确保您可以在'InitialViewController'类的'dealloc'方法中添加'NSLog()'调用 – tkanzakic