简体   繁体   English

如何在iOS中的当前ViewController之前找到所有View Controller?

[英]How to find all the view controllers before my current viewcontroller in iOS?

There are different paths which a user can take to get to a particular view controller in my app. 用户可以使用不同的路径来访问我的应用程序中的特定视图控制器。
I want to know the exact path taken by the User to get to the current view controller. 我想知道用户到达当前视图控制器所采用的确切路径。

Any suggestion would be highly appreciated. 任何建议将不胜感激。

I had similar issue in one of my projects and I created a singleton class which maintains a stack of ViewControllers. 在我的一个项目中,我遇到了类似的问题,并且创建了一个单例类,该类维护着一组ViewController。 Each ViewController is responsible for pushing and popping itself from the stack. 每个ViewController负责将自身推入堆栈并从堆栈中弹出。 Thus, we queried stack whenever we wanted to have flow that user followed. 因此,只要我们希望用户遵循该流程,我们就会查询堆栈。

It worked pretty fine for us. 它对我们来说很好。

You can check your controller by comparing it, Put your desired class instead of "XYZViewController" 您可以通过比较来检查控制器,将所需的类而不是“ XYZViewController”

for (UIViewController * aController in self.navigationController.viewControllers)
    {
        if (aController isKindOfClass:[XYZViewController class])
        {
            //You can do your work here
        }
    }

You can use the navigation stack in this way to get to know which viewController are there before you reach certain View controller. 您可以通过这种方式使用导航堆栈,以在到达某些View控制器之前了解哪个viewController。

Here is the Code : 这是代码:

for (UIViewController *vc in self.navigationController.viewControllers) {
    NSLog(@"vc desc : %@", vc.description);
}

But if you want to show a label , if the user come from a certain VC and not to show the label when come to the VC from other ViewController, Then use a boolean in the ViewController in which you need to show the label, then set the boolean as YES, while pushing from previous VC and check that boolean to show the label. 但是,如果要显示标签,如果用户来自某个VC,并且从其他ViewController进入VC时不显示标签,则在需要显示标签的ViewController中使用布尔值,然后设置从上一个VC推送时,布尔值为YES,并检查该布尔值以显示标签。

In the current view controller's viewDidAppear() , viewWillAppear() or the viewDidLoad() method use the following code. 在当前视图控制器的viewDidAppear()viewWillAppear()viewDidLoad()方法中,使用以下代码。 I have used it my viewDidLoad() method. 我已经使用它了我的viewDidLoad()方法。

 for (int i=0;i<[self.navigationController.viewControllers count];i++)
 {
     NSLog(@"%d>>>>>>>>>%@",[self.navigationController.viewControllers objectAtIndex:i]);
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 (iOS)音频播放器作为应用程序中所有父视图控制器上的子视图控制器 - (iOS) Audio player as child viewcontroller on all parent view controllers in the app 如何在iOS中找到当前可见的ViewController - How to find current visible viewController in iOS 如何在iOS中以编程方式从基本UIViewController向我的所有视图控制器添加视图 - How to add a view to all of my view controllers from base UIViewController programmatically in iOS 如何将表格视图固定为对话框或弹出窗口,适用于ios中的所有视图控制器 - How to fix the Table view as Dialog or Popup For all View Controllers in ios 如何将基本viewcontroller用于其他视图控制器? - How to use base viewcontroller for other view controllers? 所有视图控制器上的iOS自定义视图 - iOS custom view across all view controllers 如何在iOS中切换视图控制器? - How to switch View Controllers in iOS? 如何在将转换比例缩放到0.5%之前弹出父视图控件以在背景绘制 - How to pop parent viewcontroller to draw at background before transform scale the current view to 0.5 % iOS-将渐变作为背景添加到所有视图控制器 - iOS - Adding gradient as background to all view controllers iOS:对视图控制器的所有对象使用weak? - iOS: Use weak for all objects of view controllers?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM