3D Touch 快速操作无法使用 swift 3
3D Touch Quick Action Won't work swift 3
我正在尝试在我的应用程序中添加 3D 触摸快速操作。我在 navigationContoller 中嵌入了两个 viewContoller。当用户按下 3D 动作时,它应该将他们带到添加事件 viewController。但是我收到这个错误
could not cast value of type 'Morning_Star_2.AddEventsViewController' (0x1000a2260) to 'UINavigationController' (0x1a79cd360).
2017-05-02 02:51:36.220324-0400 Morning Star 2[3731:895126] Could not cast value of type 'Morning_Star_2.AddEventsViewController' (0x1000a2260) to '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 来作为!添加事件视图控制器。它可以工作,但它不会在我的添加 viewController 的顶部显示导航栏,如果您正常打开应用程序,它通常会显示导航栏。
Here is my main.storyboard
您不应该将 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)
}
}
}
我正在尝试在我的应用程序中添加 3D 触摸快速操作。我在 navigationContoller 中嵌入了两个 viewContoller。当用户按下 3D 动作时,它应该将他们带到添加事件 viewController。但是我收到这个错误
could not cast value of type 'Morning_Star_2.AddEventsViewController' (0x1000a2260) to 'UINavigationController' (0x1a79cd360). 2017-05-02 02:51:36.220324-0400 Morning Star 2[3731:895126] Could not cast value of type 'Morning_Star_2.AddEventsViewController' (0x1000a2260) to '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 来作为!添加事件视图控制器。它可以工作,但它不会在我的添加 viewController 的顶部显示导航栏,如果您正常打开应用程序,它通常会显示导航栏。
Here is my main.storyboard
您不应该将 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)
}
}
}