获取iOS Swift中的UIViewControllers的所有列表 [英] Get all list of UIViewControllers in iOS Swift

查看:76
本文介绍了获取iOS Swift中的UIViewControllers的所有列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以获取iOS Swift Project中的所有UIViewControllers.我想获取所有UIViewController的数组,并检查是否存在特定的UIViewController.我只需要找到项目中是否存在特定的UIViewController.

Is there any way to fetch all UIViewControllers in iOS Swift Project. I want to get array of all the UIViewControllers and check whether particular UIViewController exists or not.I have to just find the particular UIViewController exists or not in project.

推荐答案

您可以使用以下代码来实现.

You can do it with below code.

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate

if let viewControllers = appDelegate.window?.rootViewController?.presentedViewController
{
    // Array of all viewcontroller even after presented
}
else if let viewControllers = appDelegate.window?.rootViewController?.childViewControllers
{
    // Array of all viewcontroller after push                            
}

Swift 4.2(XCode 10)

let appDelegate = UIApplication.shared.delegate as! AppDelegate

if (appDelegate.window?.rootViewController?.presentedViewController) != nil
{
    // Array of all viewcontroller even after presented
}
else if (appDelegate.window?.rootViewController?.children) != nil
{
    // Array of all viewcontroller after push
}

这篇关于获取iOS Swift中的UIViewControllers的所有列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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