AppDelegate提供两次视图

时间:2018-03-06 15:00:15

标签: ios swift uiviewcontroller uinavigationcontroller appdelegate

我正在为我的应用程序实现快速操作,为此我需要从应用程序委托中呈现viewcontrollers。我使用这样的代码:

let viewController = storyboard.instantiateViewController(withIdentifier :"MyControllerID") as! MyController
        let navController = UINavigationController.init(rootViewController: viewController)

        if let window = self.window, let rootViewController = window.rootViewController {
            var currentController = rootViewController
            while let presentedController = currentController.presentedViewController {
                currentController = presentedController
            }
            currentController.present(navController, animated: true, completion: nil)
        }

如果应用程序处于后台并且单击了快速操作,则一切正常,但如果应用尚未启动且单击快速操作,则视图将显示两次。

我在这里做错了什么?

//编辑1:此代码在函数中,函数在applicationDidBecomeActive中调用 在didFinishLaunchingWithOptions中,我检查应用是否是通过Quick-Actions启动的,如下所示:

if let shortcutItem = launchOptions?[UIApplicationLaunchOptionsKey.shortcutItem] as? UIApplicationShortcutItem {

        launchedShortcutItem = shortcutItem
    }

launchedShortcutItem是一个变量:

var launchedShortcutItem: UIApplicationShortcutItem?

//编辑2:对于那些不知道我的意思的人来说,“快速操作”是针对他们的Apple页面:GuidelineDocumentation

0 个答案:

没有答案