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"
What is wrong?
Check Is Initial View Controller in the Attributes Inspector.
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?
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!
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.
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.
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.
Using Interface Builder :
Check if ' Is initial view controller ' is set. You can set it using below steps :
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
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;
}
}
I get this error when I change the the storyboard file name " Main.storyboard " TO: " XXX.storyboard "
The solution for me was:
Good Luck
产品“清洁”是我的解决方案。
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
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. :)
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:
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.
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.
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
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
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:
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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.