iOS 7 - Failing to instantiate default view controller

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

    I have experienced this with my Tab Bar Controller not appearing in the Simulator along with a black screen. I did the following in order for my app to appear in the Simulator.

    1. Go to Main.storyboard.
    2. Check the Is Initial View Controller under the Attributes inspector tab.

    If you accidentally deleted that view controller, or otherwise made it not the default, then you’ll see the error “Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set?” when your app launches, along with a plain black screen.

    To fix the problem, open your Main.storyboard file and find whichever view controller you want to be shown when your app first runs. When it’s selected, go to the attributes inspector and check the box marked “Is Initial View Controller”. You should see a right-facing arrow appear to the left of that view controller, showing that it’s your storyboard’s entry point.

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

    I get this error when I change the the storyboard file name "Main.storyboard" TO: "XXX.storyboard"

    The solution for me was:

    • Product->Clean
    • CHANGE: Supporting Files -> info.plist -> Main storyboard file base name -> Main TO: XXX

    Good Luck

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

    None of the above solved the issue for me. In my case it was not also setting the correct application scene manifest.

    I had to change LoginScreen used to be Main

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

    Product "Clean" was the solution for me.

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

    Setup the window manually,

    - (void)applicationDidBecomeActive:(UIApplication *)application
    {
        if (!application.keyWindow.rootViewController) 
         {
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    
            UIViewController *myViewController= [storyboard instantiateViewControllerWithIdentifier:@"myViewController identifier"];
    
             application.keyWindow.rootViewController = myViewController;
         }
    }
    
    0 讨论(0)
  • 2020-11-28 03:39

    If you have been committing your code to source control regularly, this may save you the hassle of creating a new Storyboard and possibly introducing more problems...

    I was able to solve this by comparing the Git source code of the version that worked against the broken one. The diff showed that the first line should contain the Id of the initial view controller, in my case, initialViewController="Q7U-eo-vxw". I searched through the source code to be sure that the id existed. All I had to do was put it back and everything worked again!

    <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="5056" systemVersion="13E28" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" initialViewController="Q7U-eo-vxw">
        <dependencies>
            <deployment defaultVersion="1296" identifier="iOS"/>
            <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/>
        </dependencies>
        <scenes>
    

    Here are some steps that can help you troubleshoot:

    1. Right click the failing Storyboard and use Source Control > Commit... to preserve your changes since the last commit.
    2. Try right clicking your failing Storyboard and use "Open As > Source Code" to view the XML of the storyboard.
    3. In the document element, look for the attribute named "initialViewController". If it is missing, don't worry, we'll fix that. If it is there, double click the id that is assigned to it, command-c to copy it, command-f command-v to search for it deeper in the document. This is the identifier of the controller that should provide the initial view. If it is not defined in the document then that is a problem - you should remove it from the document tag, in my case initialViewController="Q7U-eo-vxw".
    4. Go to Xcode menu item called View and choose Version Editor > Show Comparison View
    5. This shows your local version on the left and the historical version on the right. Click on the date beneath the historical version to get a list of the commits for this story board. Choose one that you know worked and compare the document element. What is the id of the *initialViewController? Is it different? If so, try editing it back in by hand and running. xcode historical compare tool in action
    0 讨论(0)
提交回复
热议问题