UISplitViewController as a child of a custom tab bar controller

I followed this tutorial to create a custom tab bar controller for an iPad app as I would like to use a vertical tab bar. However, I would like one of the tabs to represent UISplitViewController

, while the others just represent UIViewControllers

. My questions:

1) Will it be accepted in the app store? Apple's documentation currently states the addition UISplitViews

as child views are deprecated, but can be implemented with specific containers. Has anyone had any experience?

2) Here is an excerpt from my custom tab bar controller. If the secondViewController represents a UISplitView, can I leave it as it is? I mean it works when I run it, but is that acceptable?

class CustomTabBarController: UIViewController {

    @IBOutlet weak var tabView: UIView!
    @IBOutlet var tabButtons: [UIButton]!

    var firstViewController: UIViewController!
    var secondViewController: UISplitViewController!
    var thirdViewController: UIViewController!
    var viewControllerArray: [UIViewController]!
    var selectedTabIndex: Int = 0

    override func viewDidLoad() {
        super.viewDidLoad()

        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        firstViewController = storyboard.instantiateViewController(withIdentifier: "firstVC")
        secondViewController = storyboard.instantiateViewController(withIdentifier: "secondVC") as! UISplitViewController
        thirdViewController = storyboard.instantiateViewController(withIdentifier: "thirdVC")
        viewControllerArray = [firstViewController, secondViewController, thirdViewController]

        tabButtons[selectedTabIndex].isSelected = true
        didPressTab(tabButtons[selectedTabIndex])    
    }

      

3) I can't figure out what (if anything) is needed in AppDelegate

? Again seems to work fine, but just wondering if it's safe.

Thank.

+3


source to share


1 answer


1) I believe Apple is simply recommending against this as potentially bad design as they refer to Human Interface Guidelines . You don't always have to agree with their recommendations, and it is very rare that your app will be rejected for design choices - the only instances from my head will mimic the App Store or other OS functionality.

2) If, as you say, it works, I don't see a glaring problem.

3) Again, if it works, you may not need to do anything. But here's how Apple sets up its template for the Master-Detail app:

storyboard

If your splitViewController is set up this way and you want the same functionality as this template, this is how you can get it.



First add this to the very bottom of the AppDelegate.swift:

extension AppDelegate: UISplitViewControllerDelegate {

    func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController:UIViewController, onto primaryViewController:UIViewController) -> Bool {
        guard let secondaryAsNavController = secondaryViewController as? UINavigationController else { return false }
        guard let topAsDetailController = secondaryAsNavController.topViewController as? DetailViewController else { return false }
        if topAsDetailController.detailItem == nil {
            // Return true to indicate that we have handled the collapse by doing nothing; the secondary controller will be discarded.
            return true
        }
        return false
    }
}

      

Then add this to the end of the viewDidLoad in the CustomTabBarController:

guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {return}

let navigationController = secondViewController.viewControllers[secondViewController.viewControllers.count-1] as! UINavigationController
navigationController.topViewController!.navigationItem.leftBarButtonItem = secondViewController.displayModeButtonItem

secondViewController.delegate = appDelegate

      

0


source







All Articles