导航控制器问题

发布于 2024-10-19 02:24:42 字数 732 浏览 1 评论 0原文

我有一个普通的视图控制器,我想向它添加一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烂柯人 2024-10-26 02:24:42

因为没有视图可以弹出。当您尝试弹出视图控制器时,堆栈中应该有一些视图,即您调用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文