1
votes

I have a storyboard with this situation;

My Storyboard

The root view controller is a UISplitViewController with:

  • MASTER: a UITabBarController
    • 0 ->UINavigationController -> ...other ViewControllers
    • 1 ->UINavigationController -> ...other ViewControllers
  • DETAIL: a UINavigationController -> a DetailViewControler

With this hierarchy the segue showDetail from last viewcontroller in master to the Navigation Controller in Detail doesn't work because the Detail is presented Modally in a Collapsed environment instead of presenting it with a push. I think this behavior comes from the Tab Bar Controller because it isn't a Container like a UINavigationController. In fact if i remove the tab bar and set a navigation as Master of Split View Controller it works like usual.

What can i do for using a tab bar like Master of Split View Controller and get the right behavior of showDetail segue in a collapsed environment?

P.S.: for right behavior i mean pushing the Detail in the Master Navigation Controller in a horizontal compact environment (iPhone 6 plus Portrait).

2
Make the segue from Master-side view controllers directly to the detail view controller, not the navigation controller in which the detail VC is embedded.pbasdf
It doesn't work: the detail is presented modally and it is not pushed in the navigation controller stack of the master.Andorath
Hey, @Andorath were you able to figure this out? I`m having the same problem.animaonline
Yes i have added an answer below. I hope this can help you.Andorath

2 Answers

0
votes

I solved this issue overriding these methods of the UISplitViewControllerDelegate and implementing inside them all the behavior i want from the SplitViewController:

  • primaryViewControllerForCollapsingSplitViewController
  • splitViewController:collapseSecondaryViewController:ontoPrimaryViewController
  • primaryViewControllerForExpandingSplitViewController
  • splitViewController:separateSecondaryViewControllerFromPrimaryViewController:

I suggest you to take a look at UISplitViewController Documentation because it explains very well the behavior of the Split Controller:

UISplitViewController Documentation

You can find what you need here:

The split view controller performs collapse and expand transitions when its size class toggles between horizontally regular and horizontally compact. During these transitions, the split view controller changes how it displays its child view controllers. When changing from horizontally regular to horizontally compact, the split view controller collapses one view controller onto the other. When changing from horizontally compact back to horizontally regular, it expands the interface again and displays one or both of its child view controllers depending on the display mode. When transitioning to a collapsed interface, the split view controller works with its delegate to manage the transition. At the end of a collapse transition, the split view controller normally shows only the content from its primary view controller. You can change this behavior by implementing the primaryViewControllerForCollapsingSplitViewController: method in your split view controller delegate. You might use that method to specify the secondary view controller or an entirely different view controller—perhaps one better suited for display in a horizontally compact environment. If you want to perform any additional adjustments of the view controllers and view hierarchy, you can also implement the splitViewController:collapseSecondaryViewController:ontoPrimaryViewController: method in your delegate. The expansion process reverses the collapsing process by asking the delegate to designate which view controller becomes the primary view controller and to give the delegate a chance to perform the transition itself. If you implement the delegate methods for collapsing your split view interface, you should also implement the primaryViewControllerForExpandingSplitViewController: and splitViewController:separateSecondaryViewControllerFromPrimaryViewController: methods for expanding that interface. If you do not implement any of the methods, the split view controller provides default behavior to handle the collapsing and expanding transitions. For more information about the methods you use to manage the collapse and expand transitions, see UISplitViewControllerDelegate Protocol Reference.

Hope this can help you.

PS: sorry for bad english.

0
votes

During a showDetail segue the Split View Controller checks if collapsed and calls showViewController on the primary, which in this case is the tab controller which doesn't implement this method so relies on the default view controller method which is to search up the hierachy to find on that does; in this case showViewController called on the Split View Controller which implements it by firs checking if collapsed then it calls presentViewController which is why you see it as presented modally.

To solve this you could subclass the Tab Controller, implement showViewController and call it on the selected view controller, which would be the current navigation controller.

You also need to handle the collapse and separate, one way would be to implement separateSecondaryViewControllerForSplitViewController in your tab subclass and forward that on to the nav controller child that contains the detail nav controller because that is what un-hides its nav bar and pops it off the stack. You wouldn't get that behaviour if you implemented the split controllers' separateSecondary delegate method