5

I created master-detail template for the ipad application and now I want to add Tab Bar to either master view or detail view. I can easily add tab bar controller using editor->embed in ->tab bar controller. However when I run application tab bar is not showing.

Tab bar is showing in storyboard but I am also unable to add extra tab bar items. What am I doing wrong thanks?

storyboard

1 Answers1

3

You should embed the navigation controller (of either the master or detail VC) in a tab bar controller, then delete the connection between the split view controller and that navigation controller. Finally, remake the connection from the split view controller to the tab bar controller. You'll also need to make several code changes, because the template code refers to the detail controller by its hierarchy in the split view controller, which will now be different.

rdelmar
  • 102,832
  • 11
  • 203
  • 218
  • Thanks for the answer, that makes sense. However when I try to remake connection between split view controller and tab bar controller I chose relationship segue with master view controller and if I try to run application it throws exception. Have I chosen good option for the segue? – TheGuyWhoChatsWithBots May 16 '13 at 00:38
  • TheGuyWhoChatsWithBots, yeah, the segue is fine. You should add an exception breakpoint to the project so you can see what line throws the error. I don't think you need to change any code if you did this for the master controller. It might be helpful if you could post a picture of your storyboard. – rdelmar May 16 '13 at 01:11
  • I have added storyboard screenshot and the error I get is: UITabBarController topViewController]: unrecognized selector sent to instance 0x8169a40 NSInvalidArgumentException', reason: '-[UITabBarController topViewController]: unrecognized selector sent to instance 0x8169a40' *** First throw call stack: (0x1fa7012 0x13e4e7e 0x20324bd 0x1f96bbc – TheGuyWhoChatsWithBots May 16 '13 at 01:36
  • @TheGuyWhoChatsWithBots, what method is that in, and in which class? – rdelmar May 16 '13 at 01:37
  • appDelegate, method: didfinishlaunchingwithOptions: UINavigationController *masterNavigationController = splitViewController.viewControllers[0]; MasterViewController *controller = (MasterViewController *)masterNavigationController.topViewController; this line causes error: controller.managedObjectContext = self.managedObjectContext; – TheGuyWhoChatsWithBots May 16 '13 at 01:59
  • @TheGuyWhoChatsWithBots, The navigation controller is no longer the split view controller's view controller at index 0, you tab bar controller is. It should be UINavigationController *masterNavigationController = [(UITabBarController *)splitViewController.viewControllers[0] viewControllers][0]; – rdelmar May 16 '13 at 02:09
  • This worked great, thank you for your help. I have one more question, how can I add additional items on this newly created tab bar? Simple drag and drop from interface builder doesn't work – TheGuyWhoChatsWithBots May 16 '13 at 11:02