I'm building an app in which a part of the app should list all the shops in our town and show some details about them. This part works, but it relies on a split view controller, as you can see in these pictures . I also added a video of the problem.
I didn't know how to use the split view controller, really.. So what i did was the following: I set the split view controller as the initial view controller, and connected the navigation controller which should open up first as the detail view controller. The first navigation controller of the table view is set as master view controller.
The problem now is that when i start the app, i arrive at the homepage (which is good, check the video in the drive), but in the upper left corner, you can see that there is a navigation button to the table view. Is there a way to delete that button, and make my homepage navigation controller the initial view controller again?
I guess I'd have to link the split view controller differently, set the first view controller to initial view controller again, and add a segue to the split view controller, but i don't know what that segue should look like or how I should program it. There's a segue to the first view controller of the table view right now.
In my homepage view controller, this is the code for the segue pushing to the first view controller of my table view right now:
func pushRegisterViewShoppen()
{
self.performSegueWithIdentifier("SegueShoppen", sender: self)
}
let shoppen = UIButton(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
shoppen.setTitle("Shoppen", forState: .Normal)
shoppen.setTitleColor(UIColor.whiteColor(), forState: .Normal)
shoppen.addTarget(self, action: #selector(ViewController.pushRegisterViewShoppen),
forControlEvents: .TouchUpInside)
let BergStraatFoto = UIImage.init(named: "Bergstraat")
shoppen.setBackgroundImage(BergStraatFoto!, forState: .Normal)
tempView.addSubview(shoppen)
This is the prepareForSegue in the tableViewController:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showDetail" {
if let indexPath = tableView.indexPathForSelectedRow {
let winkel: Winkel
if searchController.active && searchController.searchBar.text != "" {
winkel = filteredWinkels[indexPath.row]
} else {
winkel = winkels[indexPath.row]
}
let controller = (segue.destinationViewController as! UINavigationController).topViewController as! DetailViewController
controller.detailWinkel = winkel
controller.navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem()
controller.navigationItem.leftItemsSupplementBackButton = true
controller.navigationItem.setHidesBackButton(false, animated: true)
}
}
}
Does anyone know how i could fix this? Thanks in advance!
Try this UISplitViewController's delegate method, the detail view controller gets displayed as there is not much space in the iPhone's portrait view so you need to override that using the below delegate method.
func splitViewController(splitViewController: UISplitViewController, collapseSecondaryViewController secondaryViewController:UIViewController, ontoPrimaryViewController primaryViewController:UIViewController) -> Bool {
//handle it efficiently to decide based on certain conditions.
return true
}
Try this thread which elaborates more on the problem.