Skip to content

Instantly share code, notes, and snippets.

@evgeniyd
Created September 14, 2015 09:25
Show Gist options
  • Save evgeniyd/70710fad9455d6e2e34e to your computer and use it in GitHub Desktop.
Save evgeniyd/70710fad9455d6e2e34e to your computer and use it in GitHub Desktop.
Correct sequence of loading UISplitViewController from the storyboard manually
#import "MYAppDelegate.h"
@interface MYAppDelegate () <UISplitViewControllerDelegate>
/...
@property (nonatomic, strong) UISplitViewController* splitViewController;
@end
@implementation MYAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// ...
// loading initial vc the way many folks around do
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
UIViewController *vc =[storyboard instantiateInitialViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = vc;
// set up split vc
self.splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [self.splitViewController.viewControllers lastObject];
navigationController.topViewController.navigationItem.leftBarButtonItem = self.splitViewController.displayModeButtonItem;
navigationController.topViewController.navigationItem.leftItemsSupplementBackButton = YES;
self.splitViewController.delegate = self;
self.splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;
self.splitViewController.preferredPrimaryColumnWidthFraction = 0.5;
// do any other split vc customization if needed
// this is an important part: call this _after_ split vc set up, otherwise you'd get wrong collapsed vc presented by split vc
[self.window makeKeyAndVisible];
// ...
return YES;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment