【问题标题】:Pushing multiple UIViewControllers in NavigationController在 NavigationController 中推送多个 UIViewController
【发布时间】:2014-09-11 01:52:11
【问题描述】:

我有 6 个子类 UIViewController 与带有标识符的推送序列连接。

他们走 A>B>C>D>E>F。我无法找到如何在控制器 A 中实现按钮的方法,该按钮会自动将所有控制器堆叠到控制器 F 并显示 F 控制器。堆叠应该在UINavigationController 实例中完成,而不是通过(void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated,因为如果我使用setViewControllers 方法,那么我会丢失segue 标识符。太棒了!

【问题讨论】:

    标签: ios objective-c uiviewcontroller uinavigationcontroller xcode5


    【解决方案1】:

    你应该可以用pushViewController:animated: 来做,像这样:

    // This method belongs to view controller A class
    -(void)pushToF {
        // I am assuming that A is already in the navigation controller
        UINavigationController *nav = self.navigationController;
        UIViewController *b =[self.storyboard instantiateViewControllerWithIdentifier:@"B"];
        [nav pushViewController:b animated:NO];
        UIViewController *c =[self.storyboard instantiateViewControllerWithIdentifier:@"C"];
        [nav pushViewController:c animated:NO];
        ... // And so on, until F
        UIViewController *f =[self.storyboard instantiateViewControllerWithIdentifier:@"F"];
        // You can push the last one with animation, so that end users would see it
        [nav pushViewController:f animated:YES];
    }
    

    【讨论】:

    • 完美运行,非常感谢!还有一个问题。如果我在控制器 A 上实现模态视图,并且在该模态视图之外有一个 pushToF 方法,那么代码将如何。我知道我必须首先以编程方式关闭模态视图,然后执行您编写的内容,但我不知道如何构建。感谢您的帮助。
    • @AndrejTrilavov 如果"A" 是模态的,您需要以不同于self.navigationController 的方式获取导航控制器的引用。您也可以关闭按钮,然后从 viewWillDisappear:animated: 调用 pushToF
    • 不幸的是,我在 VC 上还有其他按钮,所以 viewWillDisappear:animated: 是不可能的。我知道我必须在 self 上 dismissViewControllerAnimated:NO 并实现您提供给我的代码,但不知道如何编写它。泰!
    猜你喜欢
    • 1970-01-01
    • 2011-04-10
    • 2012-03-15
    • 2020-12-26
    • 2011-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    相关资源
    最近更新 更多