iOS 7 - Failing to instantiate default view controller

 十七虾妈妈 发布于 2023-02-07 10:18

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"

enter image description here

What is wrong?

Ashvin Ajadi.. 301

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

在此输入图像描述

8 个回答
  • 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?

      Create a new Storyboard in your project, name it something like Main_iPhoneV2 (or iPadV2 depending on your original storyboard style)

      Open the broken storyboard, click anywhere in the white area and press command-a, then command-c (select all and copy)

      Open your new storyboard and press command-v to paste the same exact setup

      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)

      Recompile, and stop pulling your hair out

    2023-02-07 10:20 回答
  • 首先单击右侧Utilities栏中的View Controller .接下来选择Attributes Inspector并确保在View Controller部分下选中'Is Initial View Controller'复选框!

    2023-02-07 10:20 回答
  • 在Attributes Inspector中检查是否为初始视图控制器.

    在此输入图像描述

    2023-02-07 10:20 回答
  • 当我改变了故事板文件名为"我得到这个错误Main.storyboard " TO:" XXX.storyboard "

    我的解决方案是:

    产品展示 - >清洁

    更改:支持文件 - > info.plist - > 主故事板文件基本名称 - > 主要 TO:XXX

    祝好运

    2023-02-07 10:20 回答
  • 如果您有一些代码,也会报告此警告:

        window = UIWindow(frame: UIScreen.mainScreen().bounds)
        window?.rootViewController = myAwesomeRootViewController
        window?.makeKeyAndVisible()
    

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

    2023-02-07 10:20 回答
  • 使用Interface Builder:

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

      选择您的视图控制器(将显示为初始屏幕).

      Utilities窗口中选择Attribute inspector.

      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;
    

    斯威夫特:

            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
    

    2023-02-07 10:20 回答
  • 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;
         }
    }
    

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

      转到Main.storyboard.

      检查" Is Initial View Controller属性"检查器选项卡下的.

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

    2023-02-07 10:21 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有