0
votes

I have iphone.storyboard and ipad.storyboard.

iPhone storyboard has UITabBarController as root view controller . Now i have to start with iPad storyboard. I need a split view controller here and apple says it has to be the root view. now i am adding a split view controller and then UITabBarController to iPad storyboard. My app is crashing due to the code -

UITabBarController *tabBarController = 
(UITabBarController *)self.window.rootViewController;
UITabBarItem *tabBarItem0 = [tabBarController.tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem1 = [tabBarController.tabBar.items objectAtIndex:1];
UITabBarItem *tabBarItem2 = [tabBarController.tabBar.items objectAtIndex:2];
UITabBarItem *tabBarItem3 = [tabBarController.tabBar.items objectAtIndex:3];

When i add a simply UITabBarController with four tabs in iPad story board it works fine.

Shall i add any check for the device.. how to solve this issue as i have to use split view controller?

pls help

1
"pls help" - as soon as you format your code... - user529758

1 Answers

0
votes

You should split code for iPhone specific and iPad specific like this:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    UISplitViewController *splitViewControlelr = 
    (UISplitViewController *)self.window.rootViewController;
    // work with your split view controller
}
else
{
    UITabBarController *tabBarController = 
    (UITabBarController *)self.window.rootViewController;
    // work with your tab bar controller
}