Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the UISplitViewController have to be the root controller of an iPad app?

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!

like image 720
Ralph Caraveo Avatar asked Dec 02 '25 01:12

Ralph Caraveo


2 Answers

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

like image 180
user309305 Avatar answered Dec 03 '25 20:12

user309305


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.

like image 33
user1027493 Avatar answered Dec 03 '25 19:12

user1027493



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!