导航控制器问题
我有一个普通的视图控制器,我想向它添加一个 uinavigationcontroller ,所以:
[self.view addSubview:aNavigationController.view];
everything works, fine, aNavigationController is an IBOutlet, in the XIB, it's view controller is loaded from another xib, then in the navigation controller's view controller's class I type this:
- (IBAction)anAction {
[self.navigationController pushViewController:aViewController animated:YES];
}
everything works fine, the view changes to the aViewController view and it's animated, but when I type in aViewController's class this:
- (IBAction)anotherAction {
[self.navigationController popViewControllerAnimated:YES];
}
it crashes, why?I have a normal view controller and I want to add a uinavigationcontroller to it so:
[self.view addSubview:aNavigationController.view];
everything works, fine, aNavigationController is an IBOutlet, in the XIB, it's view controller is loaded from another xib, then in the navigation controller's view controller's class I type this:
- (IBAction)anAction {
[self.navigationController pushViewController:aViewController animated:YES];
}
everything works fine, the view changes to the aViewController view and it's animated, but when I type in aViewController's class this:
- (IBAction)anotherAction {
[self.navigationController popViewControllerAnimated:YES];
}
it crashes, why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为没有视图可以弹出。当您尝试弹出视图控制器时,堆栈中应该有一些视图,即您调用 popViewControllerAnimated 的视图之前已被推送。
因此,弹出不仅是很棒的动画,而且是通过导航控制器中的视图堆栈进行导航。在这种特殊情况下,您尝试调用该堆栈的-1st 元素,这就是崩溃的原因。
在这里深入挖掘:
http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/NavigationControllers/NavigationControllers.html#//apple_ref/doc/uid/TP40007457-CH103-SW1
Because there is no view to pop. When you're trying to pop view controller it is expected that there is some view in stack, i.e. the view from which you calling
popViewControllerAnimated
was already pushed earlier.So popping is not just awesome animation but navigation through stack of views in navigation controller. In this particular situation you're trying to call -1st element of this stack, that is the reason of the crash.
Dig deeper here:
http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/NavigationControllers/NavigationControllers.html#//apple_ref/doc/uid/TP40007457-CH103-SW1