In an iPad App i'm using the UISplitViewController. I need to force to show the master popover when the app launch in portrait mode.
Now I'm using this code and it works well on iOS 5.0.
if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
if ([[[AppDelegate sharedAppDelegate] splitViewController] respondsToSelector:[[[AppDelegate sharedAppDelegate] btnMenu] action]]) {
[[[AppDelegate sharedAppDelegate] splitViewController] performSelector:[[[AppDelegate sharedAppDelegate] btnMenu] action]];
}
}
But in iOS 5.1 (with the new type of master popover) the behaviour seems to be random. Sometimes the popover shows in fullscreen and sometimes works well.
Some suggestion for 5.1?
I use this solution:
In splitViewController in viewDidLoad set displayMode to .primaryOverlay
And in viewWillAppear set it back to .automatic
This way master view will be shown at launch of UISplitViewController and have default behaviour after orientation will change.
I struggled with this one for a while, and even now I'm not 100% happy with the solution, but it is the only thing I've been able to come up with, given the current constraints.
First, override the following delegate method:
and use it to grab a reference to the bar button item, and store it in an iVar:
Then, when you want to show the master view controller, make a call like this:
In case you want to perform this right at the start, then use some delay in order to prevent app crashing (thanks to the helpful comment):
In that case you can perform the selector right in the split view delegate method.