views:

6748

answers:

12

Hi all,

I am in kind of situation that I need to start with a tab based application and in that I need a split view for one or more tabs. But it seems that split view controller object can not be added to the tabbarController. (Although tabbar object can be added to the splitviewcontroller).

The problem can be seen otherways: I have a full screen in the left part I have a table view when any row is selected in the table a popover should come out pointing that row. Now when any row in the popover is selected the rows in this popover comes to the left under the selected row (only this row would be visible) and another popover comes out from the selected row. (Breadcrumb navigation type)

I think I am clear in what I explained. So guys any ideas or work arounds?

Please let me know if I am not clear in my question.

Thanks,

Madhup

A: 

How do you add tabbarcontroller to splitviewcontroller

eopeter
Is this a question or answer to my question ;-) ? Well if it is question of yours ask it separately. Don't ask questions in questions...
Madhup
+1  A: 

To let a tabbarcontroller appear as a master view for splitviewcontroller you should rewrite tabbarcontroller so that it will support or orientations(so say, using a category for the class UITabBarController)

Yan Cheng
so close to an answer that can be accepted but a brute force one, I am waiting for something more interesting .... ;). Well a nice try. So I upvote u.
Madhup
+8  A: 

Using the interface builder, create a split view controller and a tab bar controller and link them to your outlets:

@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@property (nonatomic, retain) IBOutlet UISplitViewController *splitViewController;

In your app delegate didFinishLaunchingWithOption, assign your split view controller to the tab bar controller:

splitViewController.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"Title" image:nil tag:0] autorelease];
NSArray *controllers = [NSArray arrayWithObjects:splitViewController,  /* other controllers go here */ nil];
tabBarController.viewControllers = controllers;
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];

This will create a tab bar controller (with only 1 tab in this case), which is displayed correctly in all orientations.

fredg
+2  A: 

I made a sample application. and found we can do it programmatically like:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

        NSMutableArray *array = [NSMutableArray array];

        NSMutableArray *tabArray = [NSMutableArray array]; 

        UISplitViewController *splitViewConntroller = [[UISplitViewController alloc] init];

        MainViewController *viewCont = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
        [array addObject:viewCont];
        [viewCont release];

        viewCont = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
        [array addObject:viewCont];
        [viewCont release];




        [splitViewConntroller setViewControllers:array];

        [tabArray addObject:splitViewConntroller];

        [splitViewConntroller release];

        array = [NSMutableArray array];

        splitViewConntroller = [[UISplitViewController alloc] init];

        viewCont = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
        [array addObject:viewCont];
        [viewCont release];

        viewCont = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
        [array addObject:viewCont];
        [viewCont release];

        [splitViewConntroller setViewControllers:array];

        [tabArray addObject:splitViewConntroller];

        [splitViewConntroller release];

        // Add the tab bar controller's current view as a subview of the window
        [tabBarController setViewControllers:tabArray];

        [window addSubview:tabBarController.view];
        [window makeKeyAndVisible];

        return YES;
    }

Hope this helps,

Thanks,

Madhup

Madhup
A: 

Hi Madhup, Can u tell ..how to call UIviewController from segmented control on the Navigation bar of the DetailViewController in a SplitViewController template

ganesh
please put ur comments and questions as added comments and please be more clear what u are asking i am not getting that....
Madhup
+1  A: 

See my post about retrofitting split view controllers to an existing tab bar interface: http://markivsblog.blogspot.com/2010/04/retrofitting-ipad-uisplitviewcontroller.html

A: 

can you upload a simple come for semotration?

Fast
@Fast I think I have posted that in my answer
Madhup
A: 

Keep in mind that OS 3.2 does not provide proper support for a splitview as a tabbar view.

You can make it "work" but it will have bugs - the biggest is that an orientation change made on another tab's view will often not propagate to the splitview tab view properly, making the view go wacky when you go back to it (left side view takes over the screen, or the barbutton item is missing, etc.).

I've reached the conclusion that I have to create my own splitview for use in a tabBarController because of this issue.

I had heard rumors that Apple was working on a fix but it's been months now and no iPad OS updates have occurred - maybe OS 4 for the iPad will address it.

Jason
Jason, can you elaborate on your approach? You're subclassing the splitviewcontroller or you're using categories? What method calls are the culprit? I've been chasing my tail trying to find the correct means of alerting the other splitviews of an orientation change. I'm not above brute force, but I'm exhausted by this point.
Greg Combs
I think I figured it out ... I catch both of the status bar orientation change notifications, then manually call the super will/did rotate if the splitview isn't the visible one. Then to take care of the popover buttons that now appear in landscape, I also manually notify the splitview delegate when we'll be transitioning from portrait to landscape and back.
Greg Combs
I wrote my own without referencing any of the built in splitviewcontroller stuff. Main gotchas for me were making sure I deal with the case of a low-mem occurring in another tab and then ensuring the the split view tab can set itself up proerply when it comes back up. Other than that the main work is in determining the "Current orientation" when you get active/shown again and adjusting the views as needed. I found that the current "Device" orientation wasn't always a good value to reference, so I grab the current orientation value from the tabbarcontroller itself.
Jason
A: 

Keep in mind that OS 3.2 does not provide proper support for a splitview as a tabbar view.

You can make it "work" but it will have bugs - the biggest is that an orientation change made on another tab's view will often not propagate to the splitview tab view properly, making the view go wacky when you go back to it (left side view takes over the screen, or the barbutton item is missing, etc.).

I've reached the conclusion that I have to create my own splitview for use in a tabBarController because of this issue.

I had heard rumors that Apple was working on a fix but it's been months now and no iPad OS updates have occurred - maybe OS 4 for the iPad will address it

i fix it, i'll post my custom SplitViewController and my custom TabBarController later

Anthony MAUGENDRE
A: 

I am having the same problem. Can you please post your custom SplitViewController and custom TabbarControlller, Anthony MAUGENDRE? I'll greatly appreciate your kindness.

Thanh Huynh
A: 

HI Anthony MAUGENDRE, could you post your solution? I'm interested too!

Daniele
A: 

You can use IB to build tabtab and modify tabs to splitviewcontroller.

-(void) makeSplitViewController {
NSMutableArray *controllers = [NSMutableArray arrayWithArray:tabBarController.viewControllers];
int index = 0;

for (UIViewController *controller in tabBarController.viewControllers) {
    if ([controller.tabBarItem.title isEqualToString:@"Stock"]) {
        stockDetailController = [[StockDetailController alloc] initWithNibName:@"StockDetailController" bundle:nil];

        stockMasterController = [[StockMasterController alloc] initWithStyle:UITableViewStylePlain]; 
        stockMasterController.navigationItem.title = date;
        stockMasterController.stockDetailController = stockDetailController;

        UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:stockMasterController] autorelease];

        splitViewController = [[UISplitViewController alloc] init];
        splitViewController.tabBarItem = controller.tabBarItem;
        splitViewController.viewControllers = [NSArray arrayWithObjects:nav, stockDetailController, nil];
        splitViewController.delegate = stockDetailController;

        [controllers replaceObjectAtIndex:index withObject:splitViewController];
    }

    index++;
}

tabBarController.viewControllers = controllers;

}

mikezang