How to Use a Uisplitviewcontroller in Swift

How to use a UISplitViewController in Swift

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

How to create UISplitViewController programmatically in Swift

if you want do it with navigationController, then try it:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
if UIDevice.current.userInterfaceIdiom == .pad {
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window!.backgroundColor = UIColor.whiteColor()
var splitViewController = UISplitViewController()
var homeViewController = HomeViewController()
var secondViewController = SecondViewController()
var homeNavigationController = UINavigationController(rootViewController:homeViewController)
var secondNavigationController = UINavigationController(rootViewController:secondViewController)
splitViewController.viewControllers = [homeNavigationController,secondNavigationController]
self.window!.rootViewController = splitViewController
self.window!.makeKeyAndVisible()
return true
} else {
// use single controller for iPhone and return that controller
}
}


Related Topics



Leave a reply



Submit