3
votes

According to Apple's documentation on the UISplitViewController (in the new iPad 3.2 SDK) it looks like they intend for you to use it only as a root controller of an app. In other words...it seams like you cannot push a UISplitViewController onto a UINavigationController because obviously the UINavigationController would need to hold the split view.

Can anyone confirm if this is a true limitation of the UISplitViewController? I was hoping to use the split view in my app a few levels deep in my UINavigationController hierarchy but it looks like I won't be able to do that unless there is a way.

Thank you!

5

5 Answers

5
votes

My app crashes whenever I try to present a UISplitViewController modally.

2
votes

This is an old post, but i found it useful to help me think in a different way, and this is how i solved the problem.

I created my splitViewController programmatically. I then tagged it with a number, and just added it as a subview to my current view.


FirstViewController* firstView = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease];    
SecondViewController* secondView = [[[SecondViewController alloc]  initWithNibName:@"SecondViewController" bundle:nil] autorelease];        
UISplitViewController* splitVC = [[UISplitViewController alloc] init];
[splitVC setDelegate:secondView];    
splitVC.viewControllers = [NSArray arrayWithObjects:firstView, secondView, nil];    
splitVC.view.tag = 99;    
[self.view addSubview:splitVC.view];

After that, splitView is displayed, but to get rid of it, i have to remove it from the view, so i created a notification between the viewcontrollers. In the main view controller I added the observer. (note: the main view controller isn't the splitViewController or one of it's views, it's the view controller that loads the splitViewController)

NSNotificationCenter *splitViewObserver = [NSNotificationCenter defaultCenter];
[splitViewObserver addObserver:self selector:@selector(removeSplitView) name:@"removeSplitView" object:nil];

in the selector "removeSplitView" i put all of the subviews of my current view through a for loop and search for a UIView class object with the tag 99 and remove it from the superview.

NSArray *subviews = [self.view subviews];

for (int i = 0; i < [subviews count]; i++) {
    if ([[subviews objectAtIndex:i] isKindOfClass:[UIView class]]) {
        UIView *tempView = [subviews objectAtIndex:i];
        if (tempView.tag == 99) {
            [[subviews objectAtIndex:i] removeFromSuperview];
        }
    }
}

In the firstView I have a method called done that posts the notification that the main ViewController is observing.

-(IBAction) done:(id)sender {       
    [fileSelectedNotification postNotificationName:@"removeSplitView" object:self];    
}

You'll also have to create the fileSelectedNotification somewhere in your app. I did this via viewDidLoad. It looks like this.

fileSelectedNotification = [NSNotificationCenter defaultCenter];

I of course also added this

NSNotiicationCenter *filesSelectedNotification;

to the .h file of this viewController.

Thus, when I push the done button (which is a bar button on my app) it removes the splitViewController from view.

Works fine. I got all this just from reading docs.

1
votes

Apple HIG says you can't. Means they've probably blocked you from doing it, so I doubt you'll get it working. some devs have written their own

1
votes

Not at all. It is possible to have a tab bar controller at the root of the hierarchy, where each tab has a split view controller, for example.

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

0
votes

Just for reference, I think this is the way to go: See this similar question.