UISplitViewController: replacing the detail view
Here’s something that might be useful to those having the same problem as I did: how to replace the detail view of an UISplitViewController
?
The problem with UISplitViewController
is that you can’t display two of them on top of each other using presentModalViewController
, if you try you will end up with an exception like this one:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Application tried to present a Split View Controllers modally <uisplitviewcontroller : 0x47b4c90>.'
reason: 'Application tried to present a Split View Controllers modally <uisplitviewcontroller : 0x47b4c90>.'
Here’s my solution:
- (void) showMoreDetail {
MoreController *more = [[MoreController alloc] initWithNibName: @"More"
bundle: nil]
[split.view removeFromSuperview];
split.viewControllers = [NSArray arrayWithObjects: menu, more, nil];
split.delegate = more;
[window addSubview: split.view];
[more release];
}
MoreController *more = [[MoreController alloc] initWithNibName: @"More"
bundle: nil]
[split.view removeFromSuperview];
split.viewControllers = [NSArray arrayWithObjects: menu, more, nil];
split.delegate = more;
[window addSubview: split.view];
[more release];
}
Hope this is useful to someone and please leave a comment if you know a better/proper way to do it.
Tarmo Lehtpuu
Tarmo is the swiss army knife Software Engineer. His deep knowledge on wide range of technologies makes him an efficient problem solver. In addition to Ruby on Rails, he enjoys developing iOS Apps.
5 Comments
cool. I just discovered the same solution and it works fine except i still run into one problem and not sure how to solve it. Maybe you have an idea or had the same problem?
When my app starts in portraitmode, it displays the first detailview flawless. When i select another item from the popover menu and the selected detailview gets loaded, the toolbarbutton stops to work.
It is still visible and clickable, but it doesn’t show the popup menu. When i rotate the device to landscape and back, it starts working again.
The weird thing is, that this only happens after the first replacement of the detailview. As soon as i rotate the view to landscape and back the popovercontroller ist working fine, even after another change of the view.
Noticed exactly the same problem with the button not working portrait mode, worked fine until replacing the splitViewController. At first I suspected somehow it’s calling the wrong IBAction or calling it on a nil, but after some debugging that didn’t seem to be the case. Instead I found that manually dismissing the current popover before trying to present a new one fixed it.
So in my – (IBAction) buttonClicked method I have the following:
[popoverController presentPopoverFromBarButtonItem: [toolbar.items objectAtIndex: 0]
permittedArrowDirections: UIPopoverArrowDirectionAny
animated: YES];
so, after to much searching and cursing, there is a light at the end of the tunnel. As it turns out apple provides a sample app with this function. Their solution is a little different though.
http://developer.apple.com/iphone/library/samplecode/MultipleDetailViews/Introduction/Intro.html
Thanks for the link Alex, as always Apple has good docs, sometimes just hard to find the right one :D I’ll check it out.
Can u pls post the sample code ????