无法设置根视图控制器

时间:2014-06-25 06:00:59

标签: ios xcode view uiviewcontroller storyboard

我一直收到警告

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

我一直在寻找修复,但我找到的所有解决方案都与我的代码相匹配。 在此先感谢它可能很简单,但我已经坚持了一段时间了。

AppDelegate.m

self.rootController = [[UITabBarController alloc] init];

DownloadTableView *view2 = [[DownloadTableView alloc] init];
view2 = [[UIStoryboard storyboardWithName:@"DownloadTableView" bundle:nil] instantiateViewControllerWithIdentifier:@"Download"];

TableViewController *view3 = [[TableViewController alloc] init];
view3 = [[UIStoryboard storyboardWithName:@"TableViewController" bundle:nil] instantiateViewControllerWithIdentifier:@"table"];

appWebView = [[WebViewController alloc] init];

view3.tabBarItem.title = @"Documents";
appWebView.title = @"Browser";
view2.title = @"Downloads";

self.rootController.viewControllers = [NSArray arrayWithObjects:appWebView, view2, view3,  nil];
self.window.rootViewController = _rootController; 

appWebView.tabBarItem.image = [UIImage imageNamed:@"Browser.png"];
view2.tabBarItem.image = [UIImage imageNamed:@"Download.png"];

_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// [_window addSubview:_rootController.view];
[_window makeKeyAndVisible];

3 个答案:

答案 0 :(得分:0)

很少有线似乎是多余的,这可能会导致问题,指出o -

self.rootController = [[UITabBarController alloc] init];

DownloadTableView *view2 = [[DownloadTableView alloc] init];
view2 = [[UIStoryboard storyboardWithName:@"DownloadTableView" bundle:nil] instantiateViewControllerWithIdentifier:@"Download"];

TableViewController *view3 = [[TableViewController alloc] init];
view3 = [[UIStoryboard storyboardWithName:@"TableViewController" bundle:nil] instantiateViewControllerWithIdentifier:@"table"];

view3.tabBarItem.title = @"Documents";

appWebView = [[WebViewController alloc] init];
appWebView.title = @"Browser";
appWebView.tabBarItem.title = @"Browser";

view2.title = @"Downloads";
self.rootController.viewControllers = [NSArray arrayWithObjects:appWebView, view2, view3,  nil];

self.window.rootViewController = self.rootController; <-----

appWebView.tabBarItem.image = [UIImage imageNamed:@"Browser.png"];
view2.tabBarItem.image = [UIImage imageNamed:@"Download.png"];

_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[_window addSubview:_rootController.view]; <-------
[_window makeKeyAndVisible];

答案 1 :(得分:0)

是否所有这些代码都被调用了

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
方法? _window 字段是否已连接到窗口属性?

P.S。还有许多无用和奇怪的线条。

答案 2 :(得分:0)

今天早上醒来的时候想出来

_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

不必要且与标签栏冲突

相关问题