iOS 7 - Failing to instantiate default view controller

前端 未结 16 2005
一生所求
一生所求 2020-11-28 03:08

I am using Xcode 5 in a newly created app and when I just create it I go for the run button e click on it, then the project gets built but it does not show in the iOS Simula

16条回答
  •  庸人自扰
    2020-11-28 03:31

    Using Interface Builder :

    Check if 'Is initial view controller' is set. You can set it using below steps :

    1. Select your view controller (which is to be appeared as initial screen).
    2. Select Attribute inspector from Utilities window.
    3. Select 'Is Initial View Controller' from View Controller section (if not).

    If you have done this step and still getting error then uncheck and do it again.

    Using programmatically :

    Objective-C :

            self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    
            UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"]; // 
    
            self.window.rootViewController = viewController;
            [self.window makeKeyAndVisible];
    
            return YES;
    

    Swift :

            self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
            let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    
            var objMainViewController: MainViewController = mainStoryboard.instantiateViewControllerWithIdentifier("MainController") as! MainViewController
    
            self.window?.rootViewController = objMainViewController
    
            self.window?.makeKeyAndVisible()
    
            return true
    

提交回复
热议问题