iOS 7 - Failing to instantiate default view controller
Check Is Initial View Controller in the Attributes Inspector.
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 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?
Product "Clean" was the solution for me.
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. :)
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.
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:
- Right click the failing Storyboard and use Source Control > Commit... to preserve your changes since the last commit.
- Try right clicking your failing Storyboard and use "Open As > Source Code" to view the XML of the storyboard.
- 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".
- Go to Xcode menu item called View and choose Version Editor > Show Comparison View
- 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.
Using Interface Builder :
Check if 'Is initial view controller' is set. You can set it using below steps :
- Select your view controller (which is to be appeared as initial screen).
- Select Attribute inspector from Utilities window.
- 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 :
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;
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