Ios 从AppDelegate遍历到其他控制器
我使用的层次结构如下所示--Ios 从AppDelegate遍历到其他控制器,ios,swift,Ios,Swift,我使用的层次结构如下所示-- UIViewController->(当前)->UINavigationController->(推)->UITableViewController。 如何从我的AppDelegate访问“UITableViewController”?在AppDelegate文件中的didFinishLaunchingWithOptions方法中添加以下行 self.window = UIWindow(frame: UIScreen.mainScreen().bounds) l
UIViewController
->(当前)->UINavigationController
->(推)->UITableViewController
。
如何从我的AppDelegate访问“
UITableViewController
”?在AppDelegate
文件中的didFinishLaunchingWithOptions
方法中添加以下行
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
var initialViewController = mainStoryboard.instantiateViewControllerWithIdentifier("myTable") as! UITableViewController //myTable is the storyboard id of your tableviewcontroller
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
在
AppDelegate
文件中的didfishlaunchingwithoptions
方法中添加以下行
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
var initialViewController = mainStoryboard.instantiateViewControllerWithIdentifier("myTable") as! UITableViewController //myTable is the storyboard id of your tableviewcontroller
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
我认为您可以首先在
AppDelegate
中定义一个nil属性:
var referenceTableVC:UITableViewController?
然后在您的UITableViewContoller
中,在方法ViewDidload()
的末尾,为属性提供引用:
var targetDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
targetDelegate.referenceTableVC = self
我认为您可以首先在
AppDelegate
中定义一个nil属性:
var referenceTableVC:UITableViewController?
然后在您的UITableViewContoller
中,在方法ViewDidload()
的末尾,为属性提供引用:
var targetDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
targetDelegate.referenceTableVC = self
我得到了答案
let window = UIApplication.sharedApplication().delegate?.window!!
if let rootVC = window!.rootViewController {
if let presentCont = rootVC.presentedViewController {
//presentCont can be any controller in my case it's 'UINavigationController' from navigation controller I can get all the controllers..
//navigationController.viewControllers
}
}
我得到了答案
let window = UIApplication.sharedApplication().delegate?.window!!
if let rootVC = window!.rootViewController {
if let presentCont = rootVC.presentedViewController {
//presentCont can be any controller in my case it's 'UINavigationController' from navigation controller I can get all the controllers..
//navigationController.viewControllers
}
}