3D触摸动作不起作用(Swift 3)



所以,我设法使一切正确地挂起。按下捷径动作时,我会在控制台中获得正确的打印。我从这里去哪里?我无法弄清楚...

这是我在应用程序委托中的代码

    var quicklaunch: Bool!
    var viewName: String?
   func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
    viewName = shortcutItem.type
    quicklaunch = true
    completionHandler(quicklaunch)
}
func applicationDidBecomeActive(application: UIApplication) {
    if quicklaunch == true {
        quicklaunch = false
        if viewName == "Messages" {
            let rootViewController = self.window?.rootViewController
            let popUpController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "FriendsVC")
            rootViewController?.present(popUpController, animated: true, completion: nil)
            print("Worked")
        }
    }  
}
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
    if quicklaunch == false {
        quicklaunch = true
        if viewName == "Messages" {
            let rootViewController = self.window?.rootViewController
            let popUpController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "FriendsVC")
            rootViewController?.present(popUpController, animated: true, completion: nil)
            print("Worked")
        }
    }
}

我如何将其弹出到正确的视图控制器?

您可以获取rootViewController,然后将所需的viewController模仿(如果您的rootViewControllerUINavigationController(将其推到导航堆栈上。

的线
let rootViewController = self.window?.rootViewController
let popUpController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "???") as! ???
rootViewController.present(popUpController, animated: true, completion: nil)

用相应的值替换???

编辑

在您的AppDelegate中制作一个名为quickLaunch和字符串变量viewName的布尔变量。然后更新以下两种方法

func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
    viewName = shortcutItem.type
    quickLaunch = true
    completionHandler(quickLaunch)
}
func applicationDidBecomeActive(application: UIApplication) {
    if quickLaunch == true {
        quickLaunch = false
        //PRESENT YOUR VIEW MODALLY HERE
    }  
}

最新更新