NavigationController.toolBar disappears when navigating

Viewed 17

I have a UIViewController wrapped in a UINavigationController that is presented as a pageSheet:

extension UIViewController {
    func embeddedToNavigationController() -> NavigationController {
        return NavigationController(rootViewController: self)
    }
}

let fileCopyViewController = FileCopyViewController()
let fileCopyNavigationController = fileCopyViewController.embeddedToNavigationController()
fileCopyNavigationController.modalPresentationStyle = .pageSheet
fileCopyNavigationController.transitioningDelegate = self
rootViewController?.present(fileCopyNavigationController, animated: true, completion: nil)

Now in the navigation controller of fileCopyViewController I need to show its UIToolBar with some buttons on it. How do I add the buttons so that they stay on the toolbar when the user navigates the navigation controller?

If I use:

toolbarItems = [item0, item1, item2, item3, item4] (using toolbarItems property of fileCopyViewController) The buttons are visble but when user navigates to another view controller inside the navigation bar, they disappear.

navigationController?.toolbarItems = [item0, item1, item2, item3, item4]
navigationController?.toolbar.items = [item0, item1, item2, item3, item4]
navigationController?.setToolbarItems([item0, item1, item2, item3, item4], animated: false)

.. Any of these combinations don't show the buttons at all.

How can I set the toolbar buttons in this case so they stay on the toolbar when a user navigates the navigationController hierarchy?

0 Answers
Related