ios跳转popToViewController

来源:互联网 发布:数据归一化处理方法 编辑:程序博客网 时间:2024/05/21 22:51

      在iOS应用开发中,页面中间的跳转最多的是通过push进入到某一ViewController中,而对于pop出页面,有的需要跳回到制定的页面,比如越级跳转,此时,看NavigationController中提供的方法,只有

1. - (nullable UIViewController *)popViewControllerAnimated:(BOOL)animated;

2. - (nullable NSArray<__kindof UIViewController *> *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated;

3. - (nullable NSArray<__kindof UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated;

三种比较常见的方法,其中方法1是指pop到上一页面,方法2是指跳转到制定页面,方法3是跳转到RootView。

而迷茫的使用方法2跳转指定页面,工程多会出现Bug,严重时会闪退。因此针对以上情况,给出以下解决方法,还希望能给小伙伴们带来福音。

1、

[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:2]animated:YES];

2、

for (UIViewController *temp in self.navigationController.viewControllers) {        if ([temp isKindOfClass:[你要跳转到的Controller class]]) {            [self.navigationController popToViewController:temp animated:YES];        }    }












1 0
原创粉丝点击