On iOS 13 Beta 5, I currently have problems with my UISplitView on iPhones.
My app starts with the detailsview off my splitview not with my masterview (look at the p
did you try this one (UISplitViewControllerDelegate):
self.preferredDisplayMode = .allVisible
&
func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController: UIViewController, onto primaryViewController: UIViewController) -> Bool {
return true;
}
Try MasterViewController_Instance.view.layoutIfNeeded()
inside Splitviewcontroller ViewDidLoad()
method. It fixed my problem.
class CustomSplitController: UISplitViewController{
override public func viewDidLoad() {
MASTER_CONTROLLER_INSTANCE.view.layoutIfNeeded()
//If you are using navigation controller in master controller try
MASTER_CONTROLLER_INSTANCE.navigationController?.view.layoutIfNeeded()
}
}
Alxlives's answer helped me. By using the debugger, I notice that in the master view controller, viewDidLoad is not called. So the delegate is never set, thus the collapse method is never called.
I fixed this by setting the delegate in awakeFromNib():
override func awakeFromNib() {
self.splitViewController?.delegate = self
}
Now the splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController: UIViewController, onto primaryViewController: UIViewController) -> Bool
is called, and if you return true, the master will be displayed.
For those who use storyboard and configure the new controller in a subclass from UIStoryboardSegue, it'll be simpler:
just before
[source presentViewController:destination animated:YES completion:nil];
,
just set destination.modalPresentationStyle = UIModalPresentationFullScreen;
, because the default is now UIModalPresentationPageSheet
.
I set the spliteViewController's delegate on appdelegate, and it worked
As many answers here leads to change in the Split View Controller starting sequence, I realized, that on compact size it performs vewDidLoad on detail controller ONLY. But awakeFromNib is called on every controller. So - I've just transfer my code from viewDidLoad to awakeFromNib and everything now is works perfectly!
override func awakeFromNib() {
super.awakeFromNib()
if let splitController = splitViewController {
splitController.delegate = self
}
}