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

时间:2016-02-29 23:10:31

标签: swift cllocation swrevealviewcontroller

我有一个用swift编写的应用程序,它显示不同视图的位置信息。我正在Select FirstName, LastName From tablPerson where LastName != "Smith" 收到位置更新(我不想使用单一类,因为即使应用程序在后台我也希望位置更新)。

现在,我正在使用AppDelegate实现侧边栏菜单以在不同视图之间切换。收到新的位置更新后,如何调用当前处于活动状态的viewController的功能来更新UI?

我搜索了很多,所有讨论如何找到当前SWRevealViewController的解决方案实际上都返回UIViewController作为当前SWRevealViewController,这对我们没有帮助。

1 个答案:

答案 0 :(得分:0)

我又给了它一个镜头,并且能够在我的应用程序中从另一个视图控制器中找到我的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)")
                    }
                }
            }
        }
    }