我在控制台得到以下错误:
应用程序在启动结束时应该有一个根视图控制器
下面是我的应用程序:didFinishLaunchWithOptions方法:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Set Background Color/Pattern
self.window.backgroundColor = [UIColor blackColor];
self.tabBarController.tabBar.backgroundColor = [UIColor clearColor];
//self.window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"testbg.png"]];
// Set StatusBar Color
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
// Add the tab bar controller's current view as a subview of the window
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
在Interface Builder中,UITabBarController的委托被连接到App委托。
有人知道怎么解决这个问题吗?
验证你的STORYBOARD文件…如果你使用IB '电线'代码到你的UI..然后刚好删除了UI元素…然后意识到,哦,你需要删除代码中的引用(在我的情况下,一个名为AbortButton的UIButton)…然后过了一会儿,应用程序就不会启动了……
问题在“故事板”文件中。在xml编辑器中打开它,寻找孤立的“关系”,这些连接器指向不应该指向的地方……
eg:
<relationships>
<关系种类=“出口” 名称=“中止按钮” 候选类=“UIButton”/>
在我的代码中已经不存在了…(然而我仍然有一个“连接器”链接在故事板文件)..
此外,我有(莫名其妙和无效的连接器从一个UIImageView或工具栏到我的主UIViewController。视图对象)…我想它也不喜欢……
底线-一个人不需要手动“编码控制器”的存在…STORYBOARD文件被破坏了。我修好了我的,宾果又完美地工作了。
顺便说一句,作为一个文本编码员。我越来越喜欢IB…踢屁股在MS Visual Studio的IDE…
我最近在用ios5 sdk构建一个项目时遇到了同样的问题。
起初,它是构建和运行正常的,但在那之后,错误出现了。
对我来说,解决办法相当简单。
所缺少的是,我的应用程序目标的摘要选项卡中的主界面属性被擦除了。所以我需要重新设置。
如果这不是重点,如果tabBarController仍然是nil,你总是可以通过编程方式创建你的窗口和根控制器。
作为备用方案,我将以下代码添加到我的项目中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if (!window && !navigationController) {
NSLog(@"Window and navigation controller not loaded from nib. Will be created programatically.");
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
UIViewController *viewController1, *viewController2;
viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController_iPhone" bundle:nil] autorelease];
viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController_iPhone" bundle:nil] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
self.window.rootViewController = self.tabBarController;
}
else {
[window addSubview:[tabBarController view]];
}
[self.window makeKeyAndVisible];
return YES;
}
只有当sho的解决方案也被实现时,这才会起作用。