我为我的应用程序编写了这段代码但是当我启动应用程序时,我收到了这条消息:
Application windows are expected to have a root view controller at the end of application launch
以下是代码:
NSMutableArray *controllers = [[NSMutableArray alloc] initWithCapacity:2];
_tabBarController = [[UITabBarController alloc]init];
ListViewController *listViewController = [[ListViewController alloc]initWithNibName:nil bundle:nil];
listViewController.title = @"Lista";
listViewController.tabBarItem.image = [UIImage imageNamed:@"list.jpg"];
InsertViewController *insertViewController = [[InsertViewController alloc]initWithNibName:nil bundle:nil];
insertViewController.title = @"Inserimento";
insertViewController.tabBarItem.image = [UIImage imageNamed:@"plus.jpg"];
[controllers addObject:insertViewController];
[controllers addObject:listViewController];
_tabBarController.viewControllers = controllers;
我试着添加这个:
UIViewController *viewController = [[UIViewController alloc] init];
self.window.rootViewController = viewController;
但是当我启动时,应用程序全部为白色,并且不会出现错误。
这是我的appdelegate.m
我有一个导入头文件并写入appdelegate.h
这个:
@interface AppDelegate : UIResponder <UIApplicationDelegate>{
UITabBarController *_tabBarController
}
答案 0 :(得分:0)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSMutableArray *controllers = [[NSMutableArray alloc] initWithCapacity:2];
_tabBarController = [[UITabBarController alloc]init];
ListViewController *listViewController = [[ListViewController alloc]initWithNibName:nil bundle:nil];
listViewController.title = @"Lista";
listViewController.tabBarItem.image = [UIImage imageNamed:@"list.jpg"];
InsertViewController *insertViewController = [[InsertViewController alloc]initWithNibName:nil bundle:nil];
insertViewController.title = @"Inserimento";
insertViewController.tabBarItem.image = [UIImage imageNamed:@"plus.jpg"];
[controllers addObject:insertViewController];
[controllers addObject:listViewController];
_tabBarController.viewControllers = controllers;
self.window.rootViewController = _tabBarController;
[self.window makeKeyAndVisible];
}
答案 1 :(得分:0)
您需要将tabBarController
设置为rootViewController
的{{1}}。要执行此操作,请在UIWindow
AppDelegate.m
方法内,在didFinishLaunchingWithOptions
行之前添加[self.window makeKeyAndVisible]
。希望这会有所帮助。