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

联系人:石虎 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>(

      )


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

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

    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];


谢谢!!!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。