Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get rid of "Splitview controller is expected to have a view controller at index 0 before it's used" error in iOS6

I'm trying to convert my app to universal for iPad support and whatever I do I can't get rid of the "Splitview controller is expected to have a view controller at index 0 before it's used!" error right after the app stars.

I'm using iOS6 as target, XCode 4.6.3. Tried all the things that I could find on this website and Google, didn't help me at all.

I want to add a TabBar controller as a Main one (left one in the Split Controller) and some other controllers as a detail one. Here is my current code in AppDelegate.m:

tabController = [[UITabBarController alloc] init];
[tabController setViewControllers:[NSArray arrayWithObjects:navAddVC, nav, svcNav, stvcNav, nil]]; 
FirstDetailViewController *fdvc = [[FirstDetailViewController alloc];
initWithNibName:@"FirstDetailViewController" bundle:nil];
UINavigationController *fdvcNav = [[UINavigationController alloc] initWithRootViewController:fdvc];
viewControllers = [[NSArray alloc] initWithObjects:tabController, fdvcNav, nil];
UISplitViewController *splitvc = [[UISplitViewController alloc] initWithNibName:nil bundle:nil];
[[splitvc view] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"splitViewControllerBG"]]];
[splitvc setViewControllers:viewControllers];
[splitvc setDelegate:fdvc];
[[self window] setRootViewController:splitvc];
[[self window] makeKeyAndVisible];

I'd appreciate any help, thanks.

like image 309
titicaca Avatar asked Aug 04 '13 04:08

titicaca


1 Answers

Thanks to @Wain I solved it.

The thing was that by setting up a background image to my split vc I was loading its view. So the solution is to set viewControllers array before the setting background color.

like image 103
titicaca Avatar answered Oct 31 '22 08:10

titicaca