Reputation: 966
I have an app that uses a UISplitViewController. When in Landscape orientation, we sometimes want to show the master view all the time and sometimes want it to auto hide as it does in portrait orientation. Currently this setting can be tweaked in app.
This all works well, except for one thing. When I change the setting, I'd like the auto-hide setting to take effect immediately, not just the next time I rotate the device (i.e. when - splitViewController:shouldHideViewController:inOrientation: is called).
Is there some way to (programmatically) force the UISplitViewController to pop out / hide the master view so that the SVC will query the splitViewController:shouldHideViewController:inOrientation: method again?
Any help would be greatly appreciated.
Upvotes: 1
Views: 8387
Reputation: 81868
There's no straight forward way.
A functional, yet a little hacky solution would be to set a delegate and record the barButtonItem passed to the delegate when showing/hiding the master. You can use it to just trigger the action on the button. But, as I said, this is not really a nice way of doing it (and may break in the future):
- (void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc
{
_buttonItem = barButtonItem;
// ...
}
- (void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)button
{
_buttonItem = nil;
// ...
}
- (void)toggleMasterVisible
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[_buttonItem.target performSelector:_buttonItem.action];
#pragma clang diagnostic pop
}
Upvotes: 3
Reputation: 2980
For an existing button, you can add this target to achieve what you want:
[button addTarget: theSplitViewController action: @selector(toggleMasterVisible:) forControlEvents:UIControlEventTouchUpInside];
I must assume that means you can just call
[theSplitViewController toggleMasterVisible: nil];
This is entirely undocumented, but it has the same behavior as the barButtonItem you get from the willHideViewController function.
Upvotes: 0