本文介绍了获取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的所有列表
发布评论