iphone - 转到应用程序中的第一个 View Controller

标签 iphone ios xcode uinavigationcontroller

我需要转到我的应用中的第一个 View 。我有一些 View 被推到堆栈上,然后是模态导航 Controller ,还有更多 View 被推到堆栈上。

我遇到的问题是使用 [[self navigationController] popToRootViewControllerAnimated:YES]; 只能返回到模态堆栈中的第一个 View 。

而且我无法让 [[self navigationController] popToViewController:.. 工作,因为真正的第一个 View Controller 无法通过 [[self navigationController] viewControllers].

关于如何实现这个的任何想法?谢谢。

最佳答案

这样做:

[[self navigationController] dismissModalViewControllerAnimated:YES];

这会让您回到模态呈现导航 Controller 的 VC。之后返回得更远取决于您如何将这些“少数 View ”推送到导航 Controller 之前。

编辑 - 深入根基的解释...

听起来那些“很少的 View ”在另一个底层导航 Controller 的堆栈上。这可能有点棘手,因为在该堆栈中返回更远的干净方法是让底层导航 Controller 弹出到它自己的根。但是它怎么知道它上面的模态 VC 已经完成了呢?

让我们将执行第二个导航 Controller 模态呈现的 View Controller 称为 VC_a。它是一个模态呈现的导航 Controller ,其最顶层的 VC 是 VC_b。当 VC_b 模态地关闭自身时,VC_a 如何知道弹出到它的导航根?

好的答案(通常)是 VC_b 决定关闭自己是有原因的 - 您的应用程序/模型中的某些条件已更改以使其决定完成。

我们也希望 VC_a 检测到这种情况。当 VC_b 被解雇时,VC_a 收到一条 viewWillAppear 消息,因为它即将被发现:

// VC_a.m

- (void)viewWillAppear:(BOOL)animated {

    [super viewWillAppear:animated];
    if (/* some app condition that's true when VC_b is done */) {
        // I must be appearing because VC_b is done, and I'm being uncovered
        // That means I'm done, too.  So pop...
        [self.navigationController popToRootViewControllerAnimated:NO];
    } else {
        // I must be appearing for the normal reason, because I was just pushed onto the stack
    }
}

关于iphone - 转到应用程序中的第一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10148244/

相关文章:

iphone - 检查 NSString 是否为 Integer

ios - 终止未捕获的异常 NSException - 连接到服务器后

iphone - 在导航栏中添加仅在当前 View 中显示的按钮。如何设置为所有 View ?

ios - 符合协议(protocol)和类的 Swift 属性

ios - RestKit 0.23.3 : mapping same key twice (or even more often) does not work

ios - 意外删除了 View Controller 。程序不会编译

ios - 如何创建具有权利的新配置文件?

android - 如何在 objective-c 中转换android方法

ios - Swift iOS - 如何找到 CollectionView 第二部分的 CGPoint x/y 值

iOS subview 自定义过渡