UINavigation 控制器 Push 和 Pop
单击自定义后退按钮后,我必须从当前视图控制器弹出到 HomeScreenViewController,该按钮作为灯箱添加在主窗口上。我使用了以下代码:
HomeScreenViewController *homeController = [[HomeScreenViewController alloc]
initWithNibName:@"HomeScreenViewController" bundle:nil];
[self.navigationController popToViewController:homeController animated:YES];
[homeController release];
我因异常而崩溃:尝试弹出到不存在的视图控制器。
如何实现?实施它需要哪些改变?
I have to pop to HomeScreenViewController from current view controller after clicking on custom back button, which is added on main window as a light box. I used following code :
HomeScreenViewController *homeController = [[HomeScreenViewController alloc]
initWithNibName:@"HomeScreenViewController" bundle:nil];
[self.navigationController popToViewController:homeController animated:YES];
[homeController release];
I got crashing with exception : Tried to pop to a view controller that doesn't exist.
How can it be implemented? What changes are required for implementing it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
显然,您正在创建导航堆栈上不存在的
HomeScreenViewController
的新实例。您必须获取现有实例并将其用作popToViewController:animated:
方法的参数。您可以通过从viewControllers
数组获取视图控制器来完成此操作,该数组是UINavigationController
上的一个属性。它们按顺序索引,因此如果视图控制器位于索引 1,则使用获取视图控制器。如果您想返回根视图控制器,请改用
popToRootViewControllerAnimated:
。Clearly you are creating a new instance of
HomeScreenViewController
which doesn't exist on the navigation stack. You will have to get the existing instance and use it as an argument forpopToViewController:animated:
method. You can do it by getting the view controller from theviewControllers
array which is a property onUINavigationController
. They are indexed in order so if the view controller is at index 1 then get the view controller usingIf you want to go back to root view controller, use
popToRootViewControllerAnimated:
instead.试试这个朋友
Try this friend
另外,不要忘记 AppDelegate (.m)
和 AppDelegate (.h)
中的这段代码:当您在应用程序中自定义很多内容时,有时可能会出现问题。
Also don't forget about this code in your AppDelegate (.m):
and in AppDelegate (.h)
It can be problem sometimes, when you customizing a lot things in your app.