如何从一个视图控制器弹出到另一个视图控制器 [英] How to pop from one view controller to another view controller

查看:157
本文介绍了如何从一个视图控制器弹出到另一个视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用iOS我现在有15个ViewControllers我想从一个ViewController弹出到另一个View Controller。

Using iOS I Have 15 ViewControllers now I want to pop from one ViewController to another View Controller.

我正在使用这段代码:

SecondViewController *Sec=[SecondViewController alloc]init];
[self.navigationController popViewController:Sec animated:YES];

这显示错误此ViewController不存在和然后我使用这段代码:

This shows error this ViewController not exist and then I am using this code:

NSArray *array = [self.navigationController viewControllers];
[self.navigationController popToViewController:[array objectAtIndex:1] animated:YES];

此代码适用于从thirdViewController弹出到secondViewController。但是当我们从第九个(第9个)ViewController弹出到第五个(第五个)ViewController然后我在第九个(第9个)ViewController中使用这个代码时发生了什么:

This code is right to pop from thirdViewController to secondViewController. But What happened when we pop from Ninth(9th)ViewController to Fifth(5th)ViewController then I am using this code in Ninth(9th)ViewController:

NSArray *array = [self.navigationController viewControllers];
[self.navigationController popToViewController:[array objectAtIndex:4] animated:YES];

它不会从第九(9)ViewController弹出到第五(第五)ViewController,除了它弹出第九(9th)ViewController到Eight(8th)ViewController。我不知道当我们使用这一行时发生了什么:

It does not pop from Ninth(9th)ViewController to Fifth(5th)ViewController apart that it pops Ninth(9th)ViewController to Eight(8th)ViewController. I don't know what happened when we use this line:

NSArray *array = [self.navigationController viewControllers];
NsLog(@"array = %@",array);

当我们在第九(9th)ViewController 。 NsLog显示:

When we use this in Ninth(9th)ViewController. NsLog shows:

array=   First(1st)ViewController;  
         Second(2nd)ViewController;
         Eight(8th)ViewController;
         Ninth(9th)ViewController;

我不知道为什么只有四个视图控制器显示。每当我使用15个视图控制器时。每个视图控制器中都会出现此问题。例如,如果我使用pop形式第十五(15)ViewController到Fifth(5th)ViewController然后相同的问题清单。

I don't know why only Four View Controllers show. Whenever I am using 15 View Controllers. This problem occurs in each view controller. For instance if I am Using pop form fifteenth(15th)ViewController to Fifth(5th)ViewController then same problem manifests.

NSArray *array = [self.navigationController viewControllers];
NsLog(@"array = %@",array);

array=     First(1st)ViewController;  
           Second(2nd)ViewController;
           fourteenth(14th)ViewController;
           fifteenth(15th)ViewController;

我想计算ViewControllers的数量,然后弹出到特定的ViewController。

I want to count Number of ViewControllers and then pop to specific ViewController.

推荐答案

for (UIViewController *controller in self.navigationController.viewControllers)
        {
            if ([controller isKindOfClass:[nameOfYourViewControllerYouWantToNavigate class]])
            {
                [self.navigationController popToViewController:controller animated:YES];

                break;
            }
        }

这篇关于如何从一个视图控制器弹出到另一个视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆