Swift 使用SWRevealViewController时调用当前UIViewController的函数

Swift 使用SWRevealViewController时调用当前UIViewController的函数,swift,cllocation,swrevealviewcontroller,Swift,Cllocation,Swrevealviewcontroller,我有一个用swift编写的应用程序,可以在不同的视图上显示位置信息。我正在AppDelegate中接收位置更新(我不想使用singleton类,因为即使应用程序在后台,我也希望位置更新) 现在,我使用SWRevealViewController实现一个侧栏菜单,在不同视图之间切换。当接收到新的位置更新时,如何调用当前处于活动状态的viewController函数来更新UI 我搜索了很多关于如何找到当前UIViewController的解决方案,实际上返回了SWRevealViewControll

我有一个用swift编写的应用程序,可以在不同的视图上显示位置信息。我正在
AppDelegate
中接收位置更新(我不想使用singleton类,因为即使应用程序在后台,我也希望位置更新)

现在,我使用
SWRevealViewController
实现一个侧栏菜单,在不同视图之间切换。当接收到新的位置更新时,如何调用当前处于活动状态的viewController函数来更新UI


我搜索了很多关于如何找到当前
UIViewController
的解决方案,实际上返回了
SWRevealViewController
作为当前
UIViewController
,但没有任何帮助。

我又尝试了一次,并且能够从另一个视图控制器在我的应用程序中找到我的viewController。但是,我无法获取我的子视图控制器应用程序委托

期待其他答案

以下是我所做的:

    let app = UIApplication.sharedApplication().delegate! as! AppDelegate
    if let nav = app.window?.rootViewController?.childViewControllers {
        nav.forEach { vc in
            if let viewControllers = vc as? UINavigationController {
                viewControllers.childViewControllers.forEach { vc in
                    if let x = vc as? ViewController {
                        print("Got it \(x)")
                    }
                }
            }
        }
    }

我又试了一次,从另一个视图控制器在我的应用程序中找到了我的视图控制器。但是,我无法获取我的子视图控制器应用程序委托

期待其他答案

以下是我所做的:

    let app = UIApplication.sharedApplication().delegate! as! AppDelegate
    if let nav = app.window?.rootViewController?.childViewControllers {
        nav.forEach { vc in
            if let viewControllers = vc as? UINavigationController {
                viewControllers.childViewControllers.forEach { vc in
                    if let x = vc as? ViewController {
                        print("Got it \(x)")
                    }
                }
            }
        }
    }

显示代码会很有帮助显示代码会很有帮助