gpt4 book ai didi

xcode - 应用程序打开导航 Controller 内的特定 ViewController

转载 作者:行者123 更新时间:2023-11-28 06:52:11 25 4
gpt4 key购买 nike

我试图让我的应用程序打开一个特定的 ViewController,该 ViewController 深入嵌入在导航 Controller 中,但不是 RootViewController。我在应用程序委托(delegate) didFinishLaunchingWithOptions 中尝试添加:

  self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyboard.instantiateViewControllerWithIdentifier("NavViewController")
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()

但这会转到 Root View Controller 。我尝试将此行更改为:

storyboard.instantiateViewControllerWithIdentifier("MainViewController")

确实打开了正确的 View Controller ,但是顶部没有导航栏需要在应用程序中导航。

最佳答案

要从 AppDelegate 访问 rootViewController,代码如下:

let rootViewController = application.windows[0].rootViewController as! UINavigationController
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let notificationVC = mainStoryboard.instantiateViewControllerWithIdentifier("identifier") as! NotificationVC
rootViewController.pushViewController(notificationVC, animated: false)

现在,它将具有 navigationBar。如果您仍然遇到问题,请告诉我。谢谢。

关于xcode - 应用程序打开导航 Controller 内的特定 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34585636/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com