How to use a UISplitViewController in Swift

倖福魔咒の 提交于 2019-12-03 06:53:26

You are so close just do the following.

Keep the split view layout with detail segues and return true for the following method and remove the rest of the code to do with the variable collapseDetailViewController.

func splitViewController(splitViewController: UISplitViewController, collapseSecondaryViewController secondaryViewController: UIViewController, ontoPrimaryViewController primaryViewController: UIViewController) -> Bool {
return true    
}

Put the following in you Master View controller

self.splitViewController!.delegate = self;

self.splitViewController!.preferredDisplayMode = UISplitViewControllerDisplayMode.AllVisible

self.extendedLayoutIncludesOpaqueBars = true  

Add self.extendedLayoutIncludesOpaqueBars = true to your detail view controller as mentioned by the previous answer. That should remove the bar appearing on your view controllers.

Also if you want some extra functionality add the following if you want your detail view to use the full screen on iPad.

navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem()
navigationItem.leftItemsSupplementBackButton = true

As for the splitViewController's master to be visible, you need to add this in splitViewController's ViewDidLoad. Else the master view controller is present as a side menu which you can drag in Portrait mode

self.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;

But, this master detail view will only be visible in iphone 6 plus and ipad only, otherwise ,it will act just like a navigation controller. As For pushing the viewController to navigation controller, you are trying to push a navigation controller to another navigation controller. I don't think it is recommended. Just move the segue from first view controller (where you input text) to second one(color view controller), instead of the second navigation controller. If you are interested to show the details in the right section for ipad and iphone6, and as a new page for other devices, you should not use this way, remove the push segue and use a delegate to pass information that data is changed and refresh UI.

Also, i don't think you might need a navigationController as the details page, just the colors viewController might be enough, if you are not interested in further navigation from the details page.

For detailed information on the behaviour of split view controller in iphone and iPad, just check https://www.raywenderlich.com/94443/uisplitviewcontroller-tutorial-getting-started

Try adding self.extendedLayoutIncludesOpaqueBars = true to your navigationController's viewDidLoad for the gap issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!