Application windows are expected to have a root view controller at the end of application launch 的解决

来源:互联网 发布:java实现解压缩zip 编辑:程序博客网 时间:2024/05/02 04:55



原因:出现的原因一般是运行时未给 self.window的 rootViewController的对象分配内存造成的,如下面类似例子

       

NSArray *item = [NSArray arrayWithObjects:nc1, nil];        _tabBar.tabBar.backgroundImage = [UIImage imageNamed:@"tabbarbg_app.png"];        [_tabBar setDelegate:self];        [_tabBar setViewControllers:item];        _tabBar.selectedIndex = 0;        [self.window setRootViewController:_tabBar];        [self.window setBackgroundColor:[UIColor whiteColor]];

解决方法: 为_tabBar添加内存分配即可

NSArray *item = [NSArray arrayWithObjects:nc1, nil];_tabBar = [[UITabBarController alloc] init];        _tabBar.tabBar.backgroundImage = [UIImage imageNamed:@"tabbarbg_app.png"];        [_tabBar setDelegate:self];        [_tabBar setViewControllers:item];        _tabBar.selectedIndex = 0;        [self.window setRootViewController:_tabBar];        [self.window setBackgroundColor:[UIColor whiteColor]];



原创粉丝点击