控制器中添加控制器的常见方法

五迷三道 提交于 2019-12-04 04:34:01

控制器中添加控制器的常见方法:

1 添加子控制器:addChildViewController:

2 modal出控制器: presentViewController:<#(nonnull UIViewController *)#> animated:<#(BOOL)#> completion:<#^(void)completion#>

3 设置为rootViewController

4 UINavgationController push出来控制器:pushViewController:<#(nonnull UIViewController *)#> animated:<#(BOOL)#>

5 UINavgationController 跳转到最新的一个控制器:(不管是push出来的还是pop出来的)

- (void)setViewControllers:(NSArray<UIViewController *> *)viewControllers animated:(BOOL)animated NS_AVAILABLE_IOS(3_0); // If animated is YES, then simulate a push or pop depending on whether the new top view controller was previously in the stack.

 用法实例:

    NSMutableArray *vcs = self.navigationController.viewControllers.mutableCopy;

    [vcs removeLastObject];

    SS_SaleStatisticsVC *vc = [[UIStoryboard storyboardWithName:@"SS_SaleStatisticsVC" bundle:nil] instantiateInitialViewController];

    [vcs addObject:vc];

    [self.navigationController setViewControllers:vcs animated:YES];

 

未完待续

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!