iOS 返回到任意界面(控制器)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/shihuboke/article/details/82056233

                      联系人:石虎 QQ:1224614774  昵称: 嗡嘛呢叭咪哄

                               QQ群:807236138  群称: iOS 技术交流学习群

一、概念

方式一 :根据指定的类名返回

    for (UIViewController *controller in self.navigationController.viewControllers) {

                    if ([controller isKindOfClass:[要返回的类名 class]]) {

                            [self.navigationController popToViewController:controller animated:YES];

                        }

         }

             ---------------------------我是分割线-------------------------------

方式二:根据栈的索引返回

    NSArray *temArray = self.navigationController.viewControllers;

    [self.navigationController popToViewController:[temArray objectAtIndex:1] animated:YES];

   打印:

        Printing description of temArray:

        <__NSArrayI 0x1054a20c0>(

        <MeasureVC: 0x10183f800>,

        <SHAskDoctorViewController: 0x104791c40>,

       <SHChooseDoctorViewController: 0x1047b8170>,

       <SHDoctorVisitsViewController: 0x10af7d640>,

       <SHMicroLetterPayViewController: 0x10bf26430>

      )

         ---------------------------我是分割线-------------------------------

方式三:类似方式一,推荐使用方式一

    NSArray *temArray = self.navigationController.viewControllers;

    SHSpecialHistoryViewController *test = [[SHSpecialHistoryViewController alloc] init];

    for(UIViewController *temVC in   temArray){

        if([temVC isKindOfClass:[test class]]) {

            [self.navigationController popToViewController:temVC animated:YES];

        }

    }

         

          ---------------------------我是分割线-------------------------------

方式四:

    AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;

    if (appDelegate.window.rootViewController) appDelegate.window.rootViewController = nil;

   SHSpecialHistoryViewController *specialHistoryVC = [[SHSpecialHistoryViewController alloc]init];

    appDelegate.window.rootViewController = [[SHNavigationController alloc] initWithRootViewController:specialHistoryVC];

           ---------------------------我是分割线-------------------------------

方式五:

   SHSpecialHistoryViewController *test = [[SHSpecialHistoryViewController alloc] init];

    [self.navigationController pushViewController:specialHistoryVC animated:YES];

   

           ---------------------------我是分割线-------------------------------

方式六:    

    dissmiss 返回根部控制器

    [self.presentingViewController.presentingViewController dismissViewControllerAnimated:NO completion:nil];

谢谢!!!

猜你喜欢

转载自blog.csdn.net/shihuboke/article/details/82056233