Xcode Swift 3d 快捷方式触摸导航栏未显示

Xcode Swift 3d Shortcuts Touch Navigation Bar not showing

所以我刚刚在我的应用程序中添加了 3d 快捷方式。现在他们打开了正确的 ViewController,但我无法浏览应用程序的其余部分。它似乎将 ViewController 打开为 modal。如何让导航栏也显示出来?

这里的代码是AppDelegate.swift

func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {

        if shortcutItem.type == "Micheal-Smith.Pathfinder-Society.charLog"
        {
            let sb = UIStoryboard(name: "Main", bundle: nil)
            let charLog = sb.instantiateViewController(withIdentifier: "CharacterLog") as! CharactersTableViewController
            let root = UIApplication.shared.keyWindow?.rootViewController

            root?.present(charLog, animated: false, completion: { 
                completionHandler(true)
            })
        }
        else if shortcutItem.type == "Micheal-Smith.Pathfinder-Society.gmTools"
        {
            let sb = UIStoryboard(name: "Main", bundle: nil)
            let charLog = sb.instantiateViewController(withIdentifier: "gmTools") as! UITabBarController
            let root = UIApplication.shared.keyWindow?.rootViewController

            root?.present(charLog, animated: false, completion: {
                completionHandler(true)
            })
        }
    }

尝试直接从故事板加载 navigationController。

let charLog = sb.instantiateViewController(withIdentifier: "NavCharacterLog") as! UINavigationController

另一种处理 VC 显示的方法是将 VC 嵌入到导航控制器中。然后,您将为 NavigationController 提供一个 Storyboard ID。然后你会把它呈现在屏幕上。这是一个例子:

let sb = UIStoryboard(name: "Main", bundle: nil)
        let charLog = sb.instantiateViewController(withIdentifier: "CharacterLog") as! UINavigationController 
        let root = UIApplication.shared.keyWindow?.rootViewController
root.present(charLog, animated: false, completion: { 
            completionHandler(true)
        })

"CharacterLog" 将被设置为 NavigationController StoryBoard ID 而不是 ViewController 你,如下面的 link 所示。

https://www.screencast.com/t/mcG5v5gvz

我也会 post 在答案中提到它,但这是我为您制作的 Github 教程的 link。

https://github.com/karpisdiem/3D-Quick-Qctions-Swift