我在控制台得到以下错误:
应用程序在启动结束时应该有一个根视图控制器
下面是我的应用程序: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的好文章,
我也有这个错误,但没有答案已经列出是解决我的问题。
在我的例子中,日志显示是因为我在另一个子线程中分配了应用程序根视图控制器。
-(BOOL) application:(UIApplication*) application didFinishLaunchingWithOptions:(NSDictionary*) launchOptions
{
...
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
...
dispatch_async(dispatch_get_main_queue(), ^{
...
[self updateTabBarTitles];
self.window.rootViewController = self.tabBarController;
...
});
});
[self.window makeKeyAndVisible];
return YES;
}
通过将rootViewController分配移动到函数的末尾—就在调用makeKeyAndVisible之前:—将导致日志消息不再显示。
{
...
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
我希望这能有所帮助。