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?
Ashvin Ajadi.. 301
在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?
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
首先单击右侧Utilities栏中的View Controller .接下来选择Attributes Inspector并确保在View Controller部分下选中'Is Initial View Controller'复选框!
在Attributes Inspector中检查是否为初始视图控制器.
当我改变了故事板文件名为"我得到这个错误Main.storyboard " TO:" XXX.storyboard "
我的解决方案是:
产品展示 - >清洁
更改:支持文件 - > info.plist - > 主故事板文件基本名称 - > 主要 TO:XXX
祝好运
如果您有一些代码,也会报告此警告:
window = UIWindow(frame: UIScreen.mainScreen().bounds) window?.rootViewController = myAwesomeRootViewController window?.makeKeyAndVisible()
在这种情况下,请转到目标设置的第一页并设置Main Interface
为空,因为您不需要应用的故事板条目.
使用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
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; } }
我已经体验过这一点,我的标签栏控制器没有出现在模拟器中,还有黑屏.为了让我的应用程序出现在模拟器中,我执行了以下操作.
转到Main.storyboard.
检查" Is Initial View Controller
属性"检查器选项卡下的.