3

My root view controller is an UISplitViewController, which has a UITableViewController as master view controller. On iPhone (compact width), it looks like a UINavigationController.

master

Tap a cell to show detail view controller

detail

Tapping the trash button would delete the current note. My problem is how to go back to the master view after that? Since it's an UISplitViewController, it can't pop the current view controller as UINavigationController does.

Ken Zhang
  • 1,334
  • 2
  • 12
  • 24

1 Answers1

4

I had a similar problem and finally found a solution. As I understand it, when in compact width, the detail navigation controller becomes a view controller of the master navigation controller. So all you have to do is:

  1. Determine if only one view is present by checking the split view controller's collapsed property. If it isn't collapsed (e.g. on iPad), you're already showing the table view in addition to the detail view.

  2. If it is collapsed (e.g. on iPhone) get a reference to the master navigation controller via the detail navigation controller and have it pop to its root view controller which, in this case the your table view controller.

This is the code I use in my detail view controller. In your case I think you just need to add this code to the button action in your detail view controller:

if splitViewController!.collapsed {
    let detailNavController = parentViewController as UINavigationController!
    let masterNavController = detailNavController.parentViewController as UINavigationController!
    masterNavController.popToRootViewControllerAnimated(true)
}

Good luck!

strangeluck
  • 856
  • 9
  • 10