I'm building a universal app using UISplitViewController and targeting iOS 9 and above. The app language is Objective-C.
Having started with the Xcode Master/Detail template and set up my views in the standard way, I'm realising that the app will be better if I keep the master view on screen at all times (on iPad), including when the device is in portrait mode. However, no matter how hard I search, I can't find anything to help me learn how this is achieved. I know this was previously achieved using splitViewController:shouldHideViewController:inOrientation:
However, this method is deprecated in iOS 9 and I can't figure out what replaces it and why. I've looked at the new delegate methods for UISplitViewController and find them completely lacking in any level of intuitiveness.
I'd really appreciate some pointers in regard to what replaces splitViewController:shouldHideViewController:inOrientation: and how it can be used to keep the master view displayed at all times on the iPad.
There is no need to specifically track orientation changes: Master and Detail will still be displayed in sequence on iPhone in portrait mode, and most iPhone in landscape mode.preferredDisplayMode:.allVisible
only affects the modes where both views can be simultaneously visible.
Swift
class SplitViewController: UISplitViewController {
override func viewDidLoad() {
super.viewDidLoad()
preferredDisplayMode = .allVisible
}
}
Obj-C
- (void)viewDidLoad {
[super viewDidLoad];
self.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;
}
iPad Portrait & iPhone 8 Plus Landscape
If anybody checks this topic lately the .allVisible was deprecated in IOS 14, use this: splitVC.preferredDisplayMode = .oneBesideSecondary
aSplitViewController.preferredDisplayMode = .oneBesideSecondary
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With