Search code examples
ipaduitableviewuitabbarcontrolleruisplitviewcontroller

How to add iPad subview controller to act like a Tab Bar


I have an app that I just got setup with a split view controller to display blogs on the ipad version of the app. The current setup is master controller is a table view to show the different articles off the blog, and the detail controller is a view controller with a webview inside used to show the content of the article. The issue is that I have a few other features in the app, and on the iPhone version, I use a tab bar controller to navigate. What would be some options to add buttons to the detail controller that would allow me to navigate to the other sections of the app? I know I can't get a Tab Bar Controller within the Split View Controller so I just need some guidance.

I know that the Engadget app is setup so that when you open in portrait mode, it shows the table view of apps, along with a controller at bottom to go to different things like photos, and when in landscape the table view is on the left and the text of the articles is on the right. I just want it set up so there is no blank page if you open in portrait mode, and have a feature to view other pages, besides just adding buttons to the navigation bar.


Solution

  • you CAN add a tabBarController to your SplitViewController's detail view. Simply create a UIViewController that responds to <UITabBarControllerDelegate> and in the xib file for that controller add a UITabBarController object and link it to your UIViewController. In your viewDidLoad add the Tab bar controller to the view:

    -(void)viewDidLoad {
    
         ...
    
         [self addChildViewController:myTabBarController];
    
         //add the tabBarController view
         [self.view addSubview:myTabBarController.view];
    
    }
    

    This UIViewController will be assigned to your detail view. this works and I've tried it before. However, whether apple would allow it? i don't know!

    EDIT:

    first of you should never call viewDidLoad yourself.

    Also, i don't think you need rootipad and detailipad as long as the controllers are linked to the SplitViewController in the xib file.

    in your RootViewiPad (master) add the following inside its viewDidLoad :

    -(void)viewDidLoad {
    
        ...
    
        if (self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
    
            //select the first row to load 
            [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionNone];
    
            //NOTE, I'm assuming that selecting the cell will load the detail view.
            //if that is not the case, you need to do what ever you need to load the 
            //detail view.
        }
    }
    

    if you want this behavior to happen every time (not only on first load) then add the code to the -(void)viewWillAppear method instead.