Since I attended Apple's iOS 5 Tech Talk World Tour in New York City (which was a lot of fun), I decided to try to use Storyboards. So far I like it. It does remove a lot of boring coding from iOS app. While playing with Storyboards, I have run into a few situations where I could not figure out "out of the box" solution. If I have time, I will try to blog about each and every one of these issues.
My first problem is related to use of Popover menus and UINavigationController on iPad. I was trying to implement following flow:
![]()

You click on "+" button, it shows Popover menu with 2 buttons. Once you click on one of the buttons, appropriate controller gets pushed on UINavigationController in detail part of the screen. It took me no time at all to create corresponding Storyboard:

The problem arises from the fact that none of "out of the box" segues can do following: hide popover + push appropriate controller on detail UINavigationController (NOTE: "Push" segue does "understand" master and detail, but it seems that it can not find a correct UINavigationController if you try to use it from Popover). Luckily, Apple allows us to create custom segues. This is what I came up with:
@interface LBPushDetailSegue : UIStoryboardSegue
@end
@implementation LBPushDetailSegue
- (void) perform {
UIWindow* w = [[[ UIApplication sharedApplication ] windows ] objectAtIndex: 0 ];
UISplitViewController* root = (UISplitViewController*)w.rootViewController;
UIViewController* detailsNavController = [ root.viewControllers objectAtIndex: 1 ];
UIViewController* detailsViewController = [ detailsNavController.childViewControllers objectAtIndex: 0 ];
if([ detailsViewController respondsToSelector: @selector( myPopoverController ) ]) {
UIPopoverController* popOverController = (UIPopoverController*)[ detailsViewController performSelector: @selector( myPopoverController )];
[ popOverController dismissPopoverAnimated: NO ];
[ detailsViewController.navigationController pushViewController: self.destinationViewController animated: YES ];
}
}
The only trick is how to get access to UIPopoverController. I achieved it by adding following to my "Detail Base" controller:
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([ segue isKindOfClass: [ UIStoryboardPopoverSegue class ]] ) {
self.myPopoverController = ((UIStoryboardPopoverSegue*)segue).popoverController;
}
}
You can download example project from https://github.com/leapingbytes/Blog-PushDetailSegue.
Share and Ejoy.

Add new comment