【问题标题】:Xcode Swift 3d Shortcuts Touch Navigation Bar not showingXcode Swift 3d 快捷方式触摸导航栏未显示
【发布时间】:2017-02-01 11:47:02
【问题描述】:

所以我刚刚在我的应用程序中添加了 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)
            })
        }
    }

【问题讨论】:

    标签: ios swift uinavigationbar shortcut 3dtouch


    【解决方案1】:

    处理 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,如下面的链接所示。

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

    我也会将其发布在答案中,但这是我为您制作的 Github 教程的链接。

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

    【讨论】:

    • 所以尝试唯一缺少的是后退按钮。当我通过普通导航或快速触摸进入该 ViewController 时,我无法返回菜单。
    • 所以我做了这个 GitHub 项目,我认为这会有所帮助。 github.com/karpisdiem/3D-Quick-Qctions-Swift
    • 太棒了。这在大多数情况下都有效。我确实得到了一个时髦的结果。所以现在我设置了 2 个快捷方式。第一个作品很漂亮。然后第二个工作,但我在控制台中收到一条消息:不鼓励在分离的视图控制器上呈现视图控制器,当我进入主菜单时,我的按钮不是标准的蓝色(略带色盲)。当我单击主菜单上的按钮时,它们会恢复正常颜色。不知道发生了什么。
    • 无论哪种方式,我都决定从头开始重建应用程序。我发现我的命名有几个不一致的地方。我必须重写整个VC。它需要基于浮点数而不是整数。因此,我必须重新设计我的 switch 语句,我需要几个我没有的选项。一些类有CoreData,其他类是后来添加的。这是一团糟,无论哪种方式,我都开始新鲜并且要清理很多。我不擅长添加我的评论行。
    【解决方案2】:

    尝试直接从情节提要加载 navigationController。

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

    【讨论】:

    • 打开应用程序然后它在加载屏幕上崩溃给出错误 libc++abi.dylib: terminating with uncaught exception of type NSException
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-27
    • 2012-06-30
    • 1970-01-01
    • 2015-10-12
    • 1970-01-01
    • 2017-05-12
    • 1970-01-01
    相关资源
    最近更新 更多