Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set? [duplicate]
Asked Answered
E

22

104

I am using Xcode in a newly created app and when I run the project it does not show in the iOS Simulator and I get the following message:

Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set?

I've Googled about it of course and everybody points out that this is happening because Xcode does not know yet which view controller is the initial one. But the weird thing is that I created the app as a page based (also tried single-view and tabbed app options) app and Xcode already had defined a Storyboard for it.

Also, when I go to the main interface option of the project the storyboard (named "Main" by Xcode itself) is set, and in the Storyboard, my view controller is set as the "Initial View Controller"

Is Initial View Controller

What is wrong?

Effluent answered 2/1, 2014 at 3:22 Comment(6)
try to set it programically...Lindyline
@Ramshad Hi, I'm kind of a newbie on iOS development. How can I do that?Effluent
https://mcmap.net/q/95179/-programmatically-set-the-initial-view-controller-using-storyboards/1603234Wage
Make sure to set the view controller to be initial view controller.Venatic
As Kashif Ahmed pointed out, you also need to open your Info.plist file as source code and edit the <key>UISceneStoryboardFile</key> string and provide there the name of your new storyboard.Root
Correct answer for 2023 is here https://mcmap.net/q/95446/-error-perhaps-the-designated-entry-point-is-not-setGoodhen
L
57

So this also happened to me too. I checked 50 times and my "Is Initial View Controller" was checked, believe me. It happened out of the blue. So how did I fix it?

  1. Create a new Storyboard in your project, name it something like Main_iPhoneV2 (or iPadV2 depending on your original storyboard style)
  2. Open the broken storyboard, click anywhere in the white area and press command-a, then command-c (select all and copy)
  3. Open your new storyboard and press command-v to paste the same exact setup
  4. Go to your project settings, change your "Main Interface" to the new Main_iPhoneV2 (If it's your iPad and you're writing a universal app, you'll have to edit the -Info.plist and look for the value "Main storyboard file base name (iPad)
  5. Recompile, and stop pulling your hair out
Loafer answered 2/1, 2014 at 3:46 Comment(3)
encountered the same problem while trying the steps listed in the Developer Basics. Created a new Storyboard, marked the new one as initial view controller and set the new one as the Main story board through the Projects Deployment Info. It magically started to work. Not sure if its some bug with Xcode. developer.apple.com/library/ios/referencelibrary/GettingStarted/…Hemelytron
This did not work or i believe will not work, unless and until the initial navigation controller is set as "is Inital View Controller".Doing
I was going to try this. But then I cleaned and built again and it workedDeplume
M
316

Check Is Initial View Controller in the Attributes Inspector.

enter image description here

Malefic answered 8/7, 2014 at 13:40 Comment(4)
Of course this is 'the way it should work'. But i have encountered the 'bug' as well, and then this does not work. Creating a new one, and copying all your stuff did work! in my case.Hypermeter
But his view controller is already set as Initial View Controller, isn't it?Jehoash
@YuraVasylenko: Its was not before, so i have indicated by mark as selected.Malefic
Just to make it a bit more detailed for those who needs it, Setting the Initial Controller for a StoryboardPhilharmonic
L
57

So this also happened to me too. I checked 50 times and my "Is Initial View Controller" was checked, believe me. It happened out of the blue. So how did I fix it?

  1. Create a new Storyboard in your project, name it something like Main_iPhoneV2 (or iPadV2 depending on your original storyboard style)
  2. Open the broken storyboard, click anywhere in the white area and press command-a, then command-c (select all and copy)
  3. Open your new storyboard and press command-v to paste the same exact setup
  4. Go to your project settings, change your "Main Interface" to the new Main_iPhoneV2 (If it's your iPad and you're writing a universal app, you'll have to edit the -Info.plist and look for the value "Main storyboard file base name (iPad)
  5. Recompile, and stop pulling your hair out
Loafer answered 2/1, 2014 at 3:46 Comment(3)
encountered the same problem while trying the steps listed in the Developer Basics. Created a new Storyboard, marked the new one as initial view controller and set the new one as the Main story board through the Projects Deployment Info. It magically started to work. Not sure if its some bug with Xcode. developer.apple.com/library/ios/referencelibrary/GettingStarted/…Hemelytron
This did not work or i believe will not work, unless and until the initial navigation controller is set as "is Inital View Controller".Doing
I was going to try this. But then I cleaned and built again and it workedDeplume
M
41

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!

Mohenjodaro answered 20/8, 2014 at 18:53 Comment(1)
This was my problem. I deleted the default view controller that my storyboard had and when I added another had to check this.Bah
S
22

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 Target > General > Deployment Info and set Main Interface to empty, since you don't need a storyboard entry for your app:

empty Main Interface

Speciosity answered 13/5, 2016 at 5:54 Comment(0)
C
16

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.

Is Initial View Controller in the Attributes Inspector.

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.

Canny answered 20/1, 2018 at 21:0 Comment(0)
T
14

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.

Steps to solve problem

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
Theotheobald answered 18/3, 2016 at 13:25 Comment(3)
If you do it programmatically, be sure to remove your storyboard from your target's Main Interface - just leave it blank. Also this should go in didFinishLaunchingWithOptions.Detrusion
@JordanH how to remove storyboard from targets Main Interface?Spoils
@Passe Select the text and hit delete, it’s in the General tabDetrusion
L
10

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;
     }
}
Lindyline answered 2/1, 2014 at 3:40 Comment(1)
Does this require to uncheck the initial viewcontroller in the storyboard?Bode
O
9

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

enter image description here

Overmantel answered 22/8, 2020 at 1:19 Comment(1)
Surprised this did not get as much votes. This will happen in practically any SceneDelegate implementation (that does not use Storyboard as initial controller).Jarlathus
S
7

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

Sikorski answered 4/2, 2015 at 11:22 Comment(0)
E
4

Product "Clean" was the solution for me.

Erbium answered 3/11, 2014 at 18:20 Comment(0)
J
4

If you added new storyboard then you have to check following points:

  1. In your plist file check value of Main storyboard file base name (iPad) or (iPhone) should be matched with your storyboard file name (do not add extension .storyboard)

  2. In storyboard there should be one view controller which set as Is initial view controller

  3. Clean and build your project. :)

enter image description here

Julianajuliane answered 16/7, 2016 at 8:44 Comment(0)
B
3

enter image description here

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

Blockade answered 2/5, 2017 at 14:46 Comment(0)
M
3

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

Mcclimans answered 5/11, 2019 at 7:29 Comment(1)
The <key>UISceneStoryboardFile</key> thing fixed it for me. Thanks.Root
P
3

Projects created in Xcode 11 and above, simply changing the Main Interface file from the project settings won't be enough.

You have to manually edit the Info.plist file and set the storyboard name for the UISceneStoryboardFile as well.

Palsy answered 22/12, 2019 at 16:48 Comment(0)
H
2

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
Hobbyhorse answered 20/11, 2014 at 8:24 Comment(0)
D
1

Check if you have the window var in the AppDelegate.

var window: UIWindow? 

And also check the storyboard of your Info.plist file.

<key>UIMainStoryboardFile</key>
<string>Main</string>

Programmatically setting the rootViewController in the AppDelegate is not going to fix the warning. You should choose whether to let to the storyboard set the view controller or do it programmatically.

Dwarf answered 12/6, 2018 at 10:34 Comment(0)
B
1

If you have scene delegate you have to check in info.plist

<key>UIApplicationSceneManifest</key>
    <dict>
        <key>UIApplicationSupportsMultipleScenes</key>
        <false/>
        <key>UISceneConfigurations</key>
        <dict>
            <key>UIWindowSceneSessionRoleApplication</key>
            <array>
                <dict>
                    <key>UISceneConfigurationName</key>
                    <string>Default Configuration</string>
                    <key>UISceneDelegateClassName</key>
                    <string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
                    <key>UISceneStoryboardFile</key>
                    <string>Login</string>
                </dict>
            </array>
        </dict>
    </dict>

I'm here loading my storyboard called Login.storyboard

plist

Burgenland answered 14/6, 2021 at 5:55 Comment(0)
W
1

If you've created a new Storyboard with a name other than "Main" there will be some problems, but it's easy to adjust...

So after you've created a new Storyboard with the desired name and you want to use it as the main story, do the following:

  1. Check box 'Is Initial View Controller' inside Attributes Inspector: 1
  2. Choose desired storyboard as 'Main Interface' for your target: 2
  3. Open project Info.plist and find a property 'Storyboard Name' where you should type your desired Storyboard name as value 3
Wilen answered 22/7, 2022 at 7:48 Comment(0)
C
1

If you are not using storyboard

Open info.plist In the info.plist file delete the following feature Information Property List -> Scene configuration -> Application Session Role -> Item 0 -> StoryBoard Name

Carma answered 24/11, 2022 at 15:16 Comment(0)
I
1

For future readers:- iOS 13, Swift 5

I set initial view controller programmatically from SceneDelegate, I got this as warning and the view controller is set perfectly. So I delete Storyboard Name from Info.plist and the warning is gone forever.

Info.plist > Application Scene Manifest > Scene Configuration > Application Session Role > Storyboard Name > Delete this one

Intrigante answered 27/1, 2023 at 5:22 Comment(0)
P
0

What worked for me in XCode 14.0.1 was, apart from setting initial view controller, to update in Build Settings: "UIKIT Main Storyboard File Base Name" to new the name of new storyboard

Phenomenon answered 28/10, 2022 at 12:28 Comment(0)
S
0

Check in the info.p list as there is the default storyboard name set and if it is similar to the storyboard name you want to run.

Solar answered 5/7, 2023 at 7:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.