gpt4 book ai didi

ios - 如何使用 Swift、iOS 7 设置 rootViewController

转载 作者:IT王子 更新时间:2023-10-29 05:05:30 26 4
gpt4 key购买 nike

我想在应用委托(delegate)中设置 rootViewController ..

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {

var rootView: MyRootViewController = MyRootViewController()
//Code to set this viewController as the root view??


return true

}

最佳答案

如果您正在使用 Storyboard 并想以编程方式设置您的 rootViewController,请首先确保 ViewController 在 Identity Inspector 中具有 Storyboard ID。然后在 AppDelegate 中执行以下操作:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

// get your storyboard
let storyboard = UIStoryboard(name: "Main", bundle: nil)

// instantiate your desired ViewController
let rootController = storyboard.instantiateViewControllerWithIdentifier("MyViewController") as! UIViewController

// Because self.window is an optional you should check it's value first and assign your rootViewController
if let window = self.window {
window.rootViewController = rootController
}

return true
}

关于ios - 如何使用 Swift、iOS 7 设置 rootViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24316966/

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