iOS 7 - Failing to instantiate default view controller

rod*_*ves 90 iphone xcode objective-c ios xcode5

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?
Run Code Online (Sandbox Code Playgroud)

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"

enter image description here

What is wrong?

Ash*_*iya 301

在Attributes Inspector中检查是否为初始视图控制器.

在此输入图像描述


小智 55

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

  • 在尝试开发人员基础知识中列出的步骤时遇到了同样的问题.创建了一个新的Storyboard,将新的Storyboard标记为初始视图控制器,并通过Projects Deployment Info将新的Storyboard设置为主故事板.它神奇地开始工作.不确定它是否与Xcode有关.https://developer.apple.com/library/ios/referencelibrary/GettingStarted/RoadMapiOS/FirstTutorial.html#//apple_ref/doc/uid/TP40011343-CH3-SW1 (2认同)

And*_*ndy 39

首先单击右侧Utilities栏中的View Controller .接下来选择Attributes Inspector并确保在View Controller部分下选中'Is Initial View Controller'复选框!


Jay*_*bey 14

使用Interface Builder:

检查是否设置了" 是否为初始视图控制器 ".您可以使用以下步骤进行设置:

  1. 选择您的视图控制器(将显示为初始屏幕).
  2. Utilities窗口中选择Attribute inspector.
  3. View Controller部分选择' Is Initial View Controller ' (如果没有).

如果您已完成此步骤并仍然收到错误 uncheck and do it again.

解决问题的步骤

以编程方式使用:

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;
Run Code Online (Sandbox Code Playgroud)

斯威夫特:

        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
Run Code Online (Sandbox Code Playgroud)

  • 如果以编程方式执行此操作,请务必从目标的主界面中删除故事板 - 只需将其留空即可.这应该在`didFinishLaunchingWithOptions`中. (3认同)

sup*_*org 14

如果您有一些代码,也会报告此警告:

    window = UIWindow(frame: UIScreen.mainScreen().bounds)
    window?.rootViewController = myAwesomeRootViewController
    window?.makeKeyAndVisible()
Run Code Online (Sandbox Code Playgroud)

在这种情况下,请转到目标设置的第一页并设置Main Interface为空,因为您不需要应用的故事板条目.


Sha*_* TK 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;
     }
}
Run Code Online (Sandbox Code Playgroud)


Con*_*ena 9

我已经体验过这一点,我的标签栏控制器没有出现在模拟器中,还有黑屏.为了让我的应用程序出现在模拟器中,我执行了以下操作.

  1. 转到Main.storyboard.
  2. 检查" Is Initial View Controller属性"检查器选项卡下的.

是属性检查器中的初始视图控制器.


Jul*_*tri 8

以上都没有为我解决这个问题。在我的情况下,它也没有设置正确的应用程序场景清单。

我不得不将 LoginScreen 更改为 Main

在此处输入图片说明


Hov*_*yan 5

当我改变了故事板文件名为"我得到这个错误Main.storyboard " TO:" XXX.storyboard "

我的解决方案是:

  • 产品展示 - >清洁
  • 更改:支持文件 - > info.plist - > 主故事板文件基本名称 - > 主要 TO:XXX

祝好运