One Quickie


Show navigation bar on push (UINavigationController->Swift)
Say you have a pretty main menu that's in a nav controller, and tapping on buttons take you to pushed view controllers. The pushed VCs need the navbar so they can go Back, but the pretty main menu doesn't need the navbar. Swift 3
class PrettyMainMenuViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationController?.delegate = self
    }
}

extension PrettyMainMenuViewController: UINavigationControllerDelegate {
    func navigationController(_ navigationController: UINavigationController, 
                              willShow viewController: UIViewController,
                              animated: Bool) {
        if viewController === self {
            navigationController.setNavigationBarHidden(true, animated: true)
        } else {
            navigationController.setNavigationBarHidden(false, animated: true)
        }
    }
}



borkware home | products | miniblog | rants | quickies | cocoaheads
Advanced Mac OS X Programming book

webmonster@borkware.com