我有 6 个子类 UIViewControllers 与带有标识符的推送 segues 连接。

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

最佳答案

您应该可以使用 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];
}

关于ios - 在 NavigationController 中推送多个 UIViewController,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24850181/

10-10 20:44
查看更多