Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Michael Lee
2,855 PointsHow do I set the root view controller in Swift?
I am not using the storyboard, and would like to programatically set the root view controller such that it is the first view controller which loads when a person launches the app.
This is my code in app delegate so far:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
// Override point for customization after application launch.
let vc = ViewController()
let navigationController = UINavigationController(rootViewController: vc)
self.window!.rootViewController = navigationController
self.window!.makeKeyAndVisible()
navigationController.setNavigationBarHidden(true, animated: false)
self.window!.backgroundColor = UIColor.whiteColor()
return true
}
However, it does not seem to be working, as I get a white screen instead of a UIViewController, black if i delete
self.window!.backgroundColor = UIColor.whiteColor()