【发布时间】:2012-11-28 11:10:15
【问题描述】:
我有基于导航的应用程序。我在应用程序didFinishLaunchingWithOptions 委托方法中创建了一个UINavigationController,如下所示:
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) 异常代码:0x654b495d 处的 KERN_INVALID_ADDRESS 崩溃的线程:0
线程 0 名称:调度队列:com.apple.main-thread
【问题讨论】:
-
将错误文本发送给我们。
-
另外,当您的 nib 与您的 View Controller 同名时,您可以使用
[[SecondViewController alloc] init];,它会默认使用同名的 nib。 -
我认为问题是当应用程序进入后台时系统正在释放
InitialViewController实例,以确保您可以在dealloc的InitialViewController方法中添加NSLog()调用类 -
UINavigationController确实保留了它的每个子UIViewcontroller对象。但是在每个 initialViewController 状态更改方法中检查 NSLogs 肯定是值得的,比如viewWillAppear。 -
UINavigationController 保留在它的子 UIViewcontroller 对象中,我可以从那里推送另一个视图控制器....
标签: ios