【问题标题】:Run a method in AppDelegate for a Controller which is not the first在 AppDelegate 中为不是第一个控制器的控制器运行方法
【发布时间】:2016-04-18 12:21:51
【问题描述】:

我正在我的应用中配置 Handoff。对于以这种方式构建的应用程序

(Entry Point) -> UINavigationController -> InterestedViewController

够了:

func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool {
        if let win = self.window {
            let navController = win.rootViewController as! UINavigationController
            let viewController = navController.topViewController as! myViewController

            viewController.restoreUserActivityState(userActivity)
    }
    return true
}

当使用 Handooff 启动应用程序时,此方法在 AppDelegate 中运行,在“myViewController”中启动方法func restoreUserActivityState(activity: NSUserActivity),一切正常。

问题是我的应用程序以另一种方式构建:

(Entry Point) -> Another ViewController with animated logo -> UINavigationController -> InterestedViewController

所以前面的代码不起作用。看不懂怎么改代码...

【问题讨论】:

    标签: ios xcode uinavigationcontroller storyboard appdelegate


    【解决方案1】:
    func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool {   // Handoff
    
        if let win = window {
            let presentationController = win.rootViewController as! PresentationController
            let navController = presentationController.presentedViewController as! UINavigationController
            let viewController = navController.topViewController as! myViewController
    
            viewController.restoreUserActivityState(userActivity)
        }
    
        return true
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多