如何在不使用导航栏的情况下将控制器从导航堆栈中弹出 [英] how to pop a controller off the navigation stack without using the navigation bar
问题描述
我正在尝试使用一些分层视图来实现导航控制器.我想使用常规的UIViewController来显示向下钻取的选项,不想使用导航栏-我想拥有自己的自定义按钮来返回上一级.
I'm trying to implement a navigation controller with some hierarchical views. I want to use a regular UIViewController to present choices for drilling down, I don't want to use the navigation bar - I want to have my own, custom buttons for returning back up a level.
我看到类似的例子:
[[self navigationController] pushViewController:nextViewController animated:YES];
和我的问题是:navigationController
是所有UIViewControllers的属性吗?不管堆栈上的视图如何,我都可以引用self.navigationController
吗?如果我处于任意视图,我可以进行包含[self.navigationController popToRootViewController animated:YES];
and my questions are these: Is navigationController
a property of all UIViewControllers? Can I refer to self.navigationController
regardless of the view that's on the stack? If I'm at an arbitrary view, can I have a button action that contains something like [self.navigationController popToRootViewController animated:YES];
根据情况,我呈现的每个视图都需要一个按钮以返回到上一个视图或根视图.我想在每个视图控制器中创建该按钮,并控制它返回到堆栈中的哪个视图.我在正确的轨道上吗?
Each view I present will need a button to return to the previous view, or to the root view, depending on the situation. I want to create that button in each view controller and control which view in the stack it returns to. Am I on the right track?
推荐答案
navigationController是否是所有UIViewControllers的属性?
Is navigationController a property of all UIViewControllers?
是的
无论堆栈上的视图如何,我都可以引用self.navigationController吗?
Can I refer to self.navigationController regardless of the view that's on the stack?
UINavigationController
堆栈上的每个UIViewController
都将在调用navigationController
时返回UINavigationController
对象.
Every UIViewController
on the UINavigationController
's stack will return the UINavigationController
object when calling navigationController
on it.
如果我处于任意视图,我可以进行包含
[self.navigationController popToRootViewControllerAnimated:YES];
是的. popToRootViewControllerAnimated:
会将用户带到UINavigationController
的根UIViewController
,您可以使用[self.navigationController popViewControllerAnimated:YES];
弹出顶部的UIViewController
.最后一个与点击Back
UIBarButtonItem
相同.
Yes. popToRootViewControllerAnimated:
will take the user to the root UIViewController
for the UINavigationController
, and you can use [self.navigationController popViewControllerAnimated:YES];
to just pop off the top UIViewController
. This last one does the same as tapping the Back
UIBarButtonItem
.
我在正确的轨道上吗?
Am I on the right track?
是:)
这篇关于如何在不使用导航栏的情况下将控制器从导航堆栈中弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!