Reputation: 422
Below is my code, I am unable to load first view controller through this suggest me without using navigation controller embedded.
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
let storyBoard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
let firstViewController = storyBoard.instantiateViewControllerWithIdentifier("LoginViewController")
self.window?.rootViewController = firstViewController
return true
}
Upvotes: 0
Views: 74
Reputation: 4855
1) make sure you are filling in the correct name for your storyboard. 2) check the identifier name for your view controller.
then,
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyboard.instantiateViewControllerWithIdentifier("LoginViewController") as UIViewController
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
return true
}
Upvotes: 1
Reputation: 506
if you use storyboard, you gotta set the initial view controller in storyboard, "self.window?.rootViewController " won't work
Upvotes: 0
Reputation: 3753
Do you need to do it via code? As your view controller is in storyboard you can just click on the view controller and tick the box to make it the initial view controller, which achieves the same thing as your code:
Upvotes: 1
Reputation: 427
let storyBoard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
change here your storyboard name.
Upvotes: 0