菜鸟教程小白 发表于 2022-12-11 18:38:55

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) -&gt; Void) {
    if let tabVC = self.window?.rootViewController as? UITabBarController {
      if shortcutItem.type == &#34;Hausaufgaben&#34; {
            tabVC.selectedIndex = 1
            tabVC.performSegue(withIdentifier: &#34;gotoHausaufgaben&#34;, 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) -&gt; Void) {
   if shortcutItem.type == &#34;Hausaufgaben&#34; {
      self.window = UIWindow(frame: UIScreen.main.bounds)
      let storyboard = UIStoryboard(name: &#34;Main&#34;, bundle: nil)
      let initialViewController = storyboard.instantiateViewController(withIdentifier: &#34;YOUR PAGE Identifier&#34;)
      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]
查看完整版本: ios - 从 AppDelegate 呈现一个 ViewController