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.