Search code examples
iosxcodeswiftipaduisplitviewcontroller

UISplitViewController: Navigating within detailView


I have an app with a SplitView that lets you add companies to a database. In the masterView the companies are shown with their respective company names. Tapping on one of these companies shows me the address in a "viewCell" (not actually a cell just a view within a viewController, just easier to explain). Below that "viewCell" is a tableView (still in the same viewController) with one row: "Employees". Tapping on that leads me to a new tableViewController that lists all the employees that I can add or that I added.

I would like to use a navBarItem to go back and forth between the CompanyDetailViewController and the EmployeesTableViewController.

On iPhone this works nicely with a transition with the automatically created "< Back" navBarItem. On iPad this does not work. It does not show any navBarItem. I know the reason (the EmployeeTableViewController "thinks" it's the detailView of the masterView, hence it does not need one), but I'd like to be able to transition back and worth with an animation.

My prepareForSegue from the CompanyDetailView to EmployeesTableViewController looks like this:

if (segue.identifier == "ShowEmployeesSegue")
{
    let controller = (segue.destinationViewController as! UINavigationController).topViewController as! EmployeesTableViewController
    controller.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem()
    controller.navigationItem.leftItemsSupplementBackButton = true

    controller.coreDataStack = coreDataStack
    controller.companyToView = companyToView as? Company
}

Update: Some Screenshots

  • iPhone: https://i.sstatic.net/ivl86.png

    1. MasterView with 3 Test Companies

    2. DetailView of Test Company 1

    3. List of employees of Test Company 1 after tapping on Employees, "< Back"-Button visible

  • iPad: https://i.sstatic.net/ObBto.png

    1. MasterView with DetailView of Test Company 1

    2. List of Employees of Test Company 1, No "< Back"-Button visible to go back to DetailView of Test Company 1


Solution

  • Based on some understanding, the following could be your solution.

    Check in the code, if the action for it is showDetailViewController:sender.

    Open the select Storyboard -> Open as Source Code. Find your object (might be by x and y).

    The working connection segue should like the below

    <connections>
                   <segue destination="UXJ-Si-1aa" kind="show" id="aDD-wp-6dZ"/>
    
    </connections>
    

    Delete the action if you might have and try again, in the following way. Select the button, cntrl + drag the pointer to your ViewController. Shown in images

    If you have segue like the below one would not work , and will not show UINavigationBar

        <connections> 
        <segue destination="UXJ-Si-1aa" kind="show" action="showDetailViewController:sender:" id="A8L-Ad-PKT"/> 
    
    </connections>
    

    enter image description here

    enter image description here