iOS 7 - Failing to instantiate default view controller

前端 未结 16 1881
一生所求
一生所求 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:27

    This warning is also reported if you have some code like:

        window = UIWindow(frame: UIScreen.mainScreen().bounds)
        window?.rootViewController = myAwesomeRootViewController
        window?.makeKeyAndVisible()
    

    In this case, go to the first page of target settings and set Main Interface to empty, since you don't need a storyboard entry for your app.

    0 讨论(0)
  • 2020-11-28 03:28

    Apart from above correct answer, also make sure that you have set correct Main Interface in General.

    0 讨论(0)
  • 2020-11-28 03:29

    Check Is Initial View Controller in the Attributes Inspector.

    enter image description here

    0 讨论(0)
  • 2020-11-28 03:30

    1st option

    if you want to set your custom storyboard instead of a default view controller.

    Change this attribute from info.plist file

    <key>UISceneStoryboardFile</key> <string>Onboarding</string>

    Onboarding would be your storyboard name

    to open this right-click on info.plist file and open as a source code

    2nd option

    1- Click on your project

    2- Select your project from the target section

    3- Move to Deployment interface section

    4- Change your storyboard section from Main Interface field

    Please remember set your storyboard initial view controller

    0 讨论(0)
  • 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"]; // <storyboard id>
    
            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
    
    0 讨论(0)
  • 2020-11-28 03:34

    First click on the View Controller in the right hand side Utilities bar. Next select the Attributes Inspector and make sure that under the View Controller section the 'Is Initial View Controller' checkbox is checked!

    0 讨论(0)
提交回复
热议问题