3D Touch Quick Action无法正常工作3

时间:2017-05-02 07:04:23

标签: ios swift3 uinavigationcontroller 3dtouch

我正在尝试在我的应用中添加3D触控快速动作。我在navigationContoller中嵌入了两个viewContoller。当用户按下3D动作时,它应该将它们带到添加事件viewController。但是我收到了这个错误

  

无法将'Morning_Star_2.AddEventsViewController'(0x1000a2260)类型的值转换为'UINavigationController'(0x1a79cd360)。   2017-05-02 02:51:36.220324-0400 Morning Star 2 [3731:895126]无法将'Morning_Star_2.AddEventsViewController'(0x1000a2260)类型的值转换为'UINavigationController'(0x1a79cd360)。

这是我的代码

func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
    if shortcutItem.type == "com.krp.addEvent" {
        let sb = UIStoryboard(name: "Main", bundle: nil)
        let addEventVC = sb.instantiateViewController(withIdentifier: "addEventVC") as! UINavigationController
        self.window?.rootViewController?.present(addEventVC, animated: true, completion: nil)
    }
}

我尝试改变了! UINavigationController为! AddEventsViewController。它可以工作,但是它不会在我添加viewController的顶部显示导航栏,因为它通常会正常打开应用程序。

Here is my main.storyboard

1 个答案:

答案 0 :(得分:2)

您不应该将AddEventsViewController投放到UINavigationController,因为它不是UINavigationController,而只是UIViewController的子类。但正如我所见,你的rootViewController是。因此,您需要将其投放到UINavigationController,然后推送AddEventsViewController,而不是现在,您将看到NavigationBar

func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
        if shortcutItem.type == "com.krp.addEvent" {
        let sb = UIStoryboard(name: "Main", bundle: nil)
        let addEventVC = sb.instantiateViewController(withIdentifier: "addEventVC") as! AddEventsViewController
        if let navigationController = window?.rootViewController as? UINavigationController {
            navigationController.pushViewController(addEventVC, animated: true)
        }
    }
}
相关问题