ios - 从 AppDelegate 呈现一个 ViewController
<p><p>我在 <code>Info.plist</code> 中设置了 3D Force Touch Action。现在我希望当 3DAction 运行时它会显示一个 ViewController ,我提供了一个 Storyboard ID,我需要在 <code>AppDelegate</code> 中执行此操作。 </p>
<p>我使用了 <code>performActionForShortCutItem</code> 函数。</p>
<pre><code>func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
if let tabVC = self.window?.rootViewController as? UITabBarController {
if shortcutItem.type == "Hausaufgaben" {
tabVC.selectedIndex = 1
tabVC.performSegue(withIdentifier: "gotoHausaufgaben", sender: nil)
}
}
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><pre><code>func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
if shortcutItem.type == "Hausaufgaben" {
self.window = UIWindow(frame: UIScreen.main.bounds)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyboard.instantiateViewController(withIdentifier: "YOUR PAGE Identifier")
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
}
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 从 AppDelegate 呈现一个 ViewController,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/41771390/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/41771390/
</a>
</p>
页:
[1]