I have a bit of a unique UISplitViewController
setup (I think). My master view controller is a table view controller within a navigation controller, which is normal. However, my detail view controller is a UITabBarController
. Each tab has a navigation controller to wrap the content within.
When the user selects a table row within the master view controller, I select a tab in the detail view controller and start pushing a view controller:
let detailViewController = masterViewController?.splitViewController
.viewControllers[1] as? UITabBarController
let selectIndex = 2
let viewController = (detailViewController.viewControllers?[selectIndex] as? UINavigationController)?.viewControllers.first
detailViewController.selectIndex = selectIndex
viewController.show(myCustomViewController)
This works great on iPad.. selecting an item in the master view controller table selects the tab in the detail view controller and pushes view controllers to it.
On iPhone, I have the master view controller shown on initial load using this post:
class MasterViewController: UIViewController {
private var collapseDetailViewController = true
override func viewDidLoad() {
super.viewDidLoad()
splitViewController?.delegate = self
}
// ...
}
extension MasterViewController: UISplitViewControllerDelegate {
func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController: UIViewController, onto primaryViewController: UIViewController) -> Bool {
return collapseDetailViewController
}
}
extension MasterViewController {
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
collapseDetailViewController = false
selectTabAndPush(index: 2, vc: myCustomViewController)
// Tried swapping the order of these but still no luck
}
}
However, selecting a row in the master view controller table literally does nothing. How can I get the detail view controller to show when a row in the master table is selected?