#StackBounty: #swift #uinavigationbar #uisplitviewcontroller UISplitView's MasterViewController and Navigation Issue

Bounty: 50

I am updating my existing app to include a SplitView for iPads.

I have it working with a UITabBar, but am having an issue with my masterViewController as it is generating a “duplicate” navigation bar that is covering my existing navigation items on all masterViewControllers (tabs), including searchBar on the search tab.

The code I have is:


class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool

    let splitViewController = self.window!.rootViewController as! UISplitViewController
    splitViewController.delegate = self
    splitViewController.preferredPrimaryColumnWidthFraction = 0.33
    splitViewController.minimumPrimaryColumnWidth = 375
    splitViewController.preferredDisplayMode = .allVisible

    return true

func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController:UIViewController, onto primaryViewController:UIViewController) -> Bool {
    return true

The reason for having this in the AppDelegate is I saw an example where placing it hear will allow me not to require the code in each of the different Master Views (each tab). Have yet to test this as still working on the first master view.

Master View

override func viewDidLoad()


    self.extendedLayoutIncludesOpaqueBars = true

    self.navigationItem.hidesBackButton = true

    // 3D Touch
    if traitCollection.forceTouchCapability == .available {
        registerForPreviewing(with: self as UIViewControllerPreviewingDelegate, sourceView: view)
        ThreeDTouch = true



func addSwitchVewButtonToNavigationBar() {
    let switchButton = UIButton(type: UIButtonType.custom)

    let editImage = UIImage(named: "CollectionButton")?.withRenderingMode(.alwaysTemplate)
    switchButton.setImage(editImage, for: .normal)
    switchButton.addTarget(self, action: #selector(SpeciesViewController.onSwitchView), for: UIControlEvents.touchUpInside)
    let switchButtonFinal = UIBarButtonItem(customView:switchButton)

    self.navigationItem.rightBarButtonItem = switchButtonFinal


@IBAction func onSwitchView(_ sender: UIBarButtonItem)
    AppDelegate.getAppState().isListViewSelected = false

    let speciesColletion = storyboard?.instantiateViewController(withIdentifier: Resource.SpeciesCollectionStoryboard) as! SpeciesCollectionViewController
    self.navigationController?.viewControllers = [speciesColletion]

Originally, the onSwitchViewButton was embedded using the IB, but did not work. This is the same system used for the addFavorite on the Detail View.

enter image description here
enter image description here

Get this bounty!!!

Leave a Reply