Andrew Kirna Andrew Kirna - 4 months ago 41
iOS Question

Where do you set preferredDisplayMode for UISplitViewController?

I'd like to create a "slide-out-menu" for a portrait application on iOS 9 that allows pan gestures to switch between modes.

I would like it to switch between the modes "Hidden - The secondary view controller is displayed onscreen and the primary view controller is off screen" and "Overlay - The secondary view controller is onscreen and the primary view controller is layered on top of it."

According to Apple's documentation, I need to set preferredDisplayMode for the UISplitViewController. Can somebody tell me where to modify this property?

Answer

Hope you created a splitViewController and set that as the rootViewController in your AppDelegate.

In viewDidLoad of the splitViewController do

- (void)viewDidLoad{ [super viewDidLoad]; masterVC = [[MasterViewController alloc] init]; detailVC = [[DetailViewController alloc] init]; NSArray *vcArray = @[masterVC, detailVC]; self.viewControllers = vcArray; self.preferredDisplayMode = UISplitViewControllerDisplayModeAutomatic; self.presentsWithGesture = YES; self.preferredPrimaryColumnWidthFraction = .10; self.delegate = (id)self; // Do any additional setup after loading the view. }

It will work for sure I have tested it. MasterViewController is the primary viewController and DetailViewController is the secondaryviewController

Comments