我在控制台得到以下错误:
应用程序在启动结束时应该有一个根视图控制器
下面是我的应用程序: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委托。
有人知道怎么解决这个问题吗?
如何为iOS5添加一个RootViewController
如果你的应用还没有使用RootViewController,
只需创建一个;)点击文件>新建>新建文件;
选择UIViewController子类
命名为RootViewController,取消用户界面With XIB(假设你已经有一个)
然后把这段代码放到你的AppDelegate:: didFinishLaunchingWithOptions中
rootViewController = [[RootViewController alloc] init];
window.rootViewController = rootViewController;
当然,你必须导入RootViewController.h并创建变量
这里有一篇关于RootViewController和AppDelegate的好文章,
在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
}
这使得警告消失,并没有真正影响你的应用程序。