gpt4 book ai didi

ios - 3D Touch Quick Action 无法快速工作 3

转载 作者:行者123 更新时间:2023-11-28 21:10:22 32 4
gpt4 key购买 nike

我正在尝试在我的应用中添加 3D 触摸快速操作。我在 navigationContoller 中嵌入了两个 viewContoller。当用户按下 3D Action 时,它应该将它们带到添加事件 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 来作为!添加事件 View Controller 。它可以工作,但它不会在我添加的 viewController 顶部显示导航栏,如果您正常打开应用程序,它通常会显示导航栏。

Here is my main.storyboard

最佳答案

你不应该施放 AddEventsViewControllerUINavigationController ,因为它不是 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)
}
}
}

关于ios - 3D Touch Quick Action 无法快速工作 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43732012/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com