Reputation: 3044
I have a standard split view controller that I want to always show it's master view on iPads.
In the master view's viewDidLoad
, I'm calling:
self.splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;
With this one line in place, I'm getting my desired effect (always shows the master). However, a strange thing also happens: The top layout guide appears to move to the top of the master view, under the navigation bar.
You can see the effect in this picture, where the first cell in the table view is partially hidden behind the navigation bar. In fact, there is a green view above it (it's a placeholder for something that will be there soon) that is totally hidden.
If I rotate the device to landscape then back to portrait, autolayout works as expected, and the views appear in the correct place:
I've tried the following in both viewDidLoad
and viewDidAppear
to try to force the views to lay out properly, but it's had no effect:
[self.splitViewController.view setNeedsLayout];
[self.splitViewController.view layoutIfNeeded];
I'm looking for any solutions/suggestions.
Upvotes: 2
Views: 500
Reputation: 1051
Well:
I was facing the same problem (I guess). But If I call:
.preferredDisplayMode=UISplitViewControllerDisplayModePrimaryOverlay
It worked like a charm.
Upvotes: 0
Reputation: 3044
I want to answer my own question with a hindsight point of view.
Apple mentioned in its documentation:
When building your app’s user interface, the split view controller is typically the root view controller of your app’s window.
And later warns:
You cannot push a split view controller onto a navigation stack. Although it is possible to install a split view controller as a child in some other container view controllers, doing is not recommended in most cases. Split view controllers are normally installed at the root of your app’s window. For tips and guidance about ways to implement your interface, see iOS Human Interface Guidelines.
Although they're not outright saying never to use UISplitViewController
as a non-root view controller, I have found that UISplitViewController
behaves unreliably when used in a non-root manner. The bug mentioned in the question is just one of many other problems you will encounter, the worse of which (in my experience) is not propagating-viewWillAppear
or -viewDidAppear
calls to child view controllers.
If you want a non-root split view, I suggest roll your own custom split view.
Upvotes: 2
Reputation: 592
I recently ran into the same issue and solved it by setting the preferredDisplayMode
on launch like so:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
...
if let splitController = self.window?.rootViewController as? UISplitViewController {
splitController.preferredDisplayMode = .allVisible
}
...
return true
}
Upvotes: 0
Reputation: 1199
The only thing that's worked for me is this:
https://stackoverflow.com/a/22084634/1919412
In my case, the issue only shows up the first time the user rotates from landscape to portrait mode (and without manually revealing the master pane first). So even though Rivera's workaround causes a jarring visual blip, it only has to happen at most once per launch.
Upvotes: 0