我在控制台得到以下错误:
应用程序在启动结束时应该有一个根视图控制器
下面是我的应用程序: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委托。
有人知道怎么解决这个问题吗?
我也有这个错误,但不像之前列出的任何答案,我的是因为我在我新生成的控制器(xcode 4.2, ios5)中取消了“loadView”方法的注释。
//Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
它甚至告诉我,该方法是为创建视图编程,但我错过了它,因为它看起来如此类似于其他方法,如viewDidLoad,我通常使用我没有抓住它。
要解决这个问题,只需删除该方法,如果你不是通过编程方式创建视图层次结构,也就是使用nib或storyboard。
在ios5.0左右有一个微小的变化,要求你有一个根视图控制器。如果您的代码基于较旧的示例代码,例如GLES2Sample,那么在这些代码示例中没有创建根视图控制器。
为了修复(例如,GLES2Sample),在applicationDidFinishLaunching中,我创建了一个根视图控制器,并将我的glView附加到它。
- (void) applicationDidFinishLaunching:(UIApplication *)application
{
// To make the 'Application windows are expected
// to have a root view controller
// at the end of application launch' warning go away,
// you should have a rootviewcontroller,
// but this app doesn't have one at all.
window.rootViewController = [[UIViewController alloc] init]; // MAKE ONE
window.rootViewController.view = glView; // MUST SET THIS UP OTHERWISE
// THE ROOTVIEWCONTROLLER SEEMS TO INTERCEPT TOUCH EVENTS
}
这使得警告消失,并没有真正影响你的应用程序。