返回 UINavigationController 的第一个索引?
我正在做一个使用 UINavigationController 的应用程序,并且我正在切换到其他 UIViewController,如下所示:
if(self.myViewController == nil){
MyViewController *aViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
self.myViewController = aViewController;
[aViewController release];
}
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.myNavController pushViewController:myViewController animated:YES];
我想这是在 UINavigationController 中创建一堆 UIViewController,也许是一个索引数组?我想知道怎样才能回头,而不需要一一回头。
例如,我正在浏览几个屏幕,并使用一个按钮,我想在第一个导航索引处返回。我还想知道如何修改索引、查看、删除以及与此问题相关的任何内容。
抱歉,如果我没有解释清楚。
I'm doing an application which uses a UINavigationController and I'm switching to other UIViewControllers as follows:
if(self.myViewController == nil){
MyViewController *aViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
self.myViewController = aViewController;
[aViewController release];
}
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.myNavController pushViewController:myViewController animated:YES];
I imagine this is creating a pile of UIViewControllers into the UINavigationController, maybe an array of indexs? I would like to know how to turn back without having to be back one by one.
For example, I'm sailing through a few screens and with a button I would like to return at the first index of navigation. I would also like know how to modify indexes, view, erase and anything pertaining to this issue.
Sorry if I have not explained well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
你问了两个问题。
首先是,如何回到我的第一个视图控制器。正如@Thomas Clayson 和@ender 所回答的,您需要navigationcontroller 对象的
popToRootViewControllerAnimated:
方法。第二个是如何移动到视图控制器堆栈中的特定索引。答案是,您可以显式设置 viewController 数组。因此,您可以取出当前的视图控制器列表,修改它,然后将其设置回 navigationController 堆栈。它将重置堆栈并让您移动到堆栈顶部的项目。
因此:
You've asked two questions.
The first is, how do I get back to my first view controller. As @Thomas Clayson and @ender have answered, you want the
popToRootViewControllerAnimated:
method of your navigationcontroller object for that.The second is how to move to a particular index in the view controller stack. The answer to that is, you can set the array of viewControllers explicitly. So you can pull out the current listing of view controllers, modify it, and set it back into the navigationController stack. It'll reset the stack and animate you moving to the top item in the stack.
Thusly:
使用这个你可以返回到任何指定的viewController。
Using this you can come back to any specified viewController.
将带您回到第一个视图控制器(根视图控制器)。
希望这有帮助
Will take you back to the very first view controller (root view controller).
Hope this helps
用这个
Use this
您应该使用
popToRootViewControllerAnimated:
来自UINavigationController
类参考:You should use
popToRootViewControllerAnimated:
FromUINavigationController
class reference:您可以返回到第一个视图,
话虽如此,您还可以删除特定的视图控制器,或者如果您查看示例,则导航到视图控制器中的特定索引。
You can return to the first view with
That being said, you can also remove a particular view controller, or navigate to a specific index in your view controller if you look at the example.