Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从AppDelegate遍历到其他控制器_Ios_Swift - Fatal编程技术网

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

}
}