fcoskun
fcoskun

Reputation: 23

NavigationBar Right Items Hides when Show inner ViewControllers

I use navigation bar with tabbarcontroller. When i push one of my tabs my navigationbar right items are hiding automatically.

How i can move my items to childs controllers?

Upvotes: 0

Views: 33

Answers (1)

a.masri
a.masri

Reputation: 2469

You can create base view controller and inherit your children classes from base view controller then call super.viewDidLoad()

1- Base controller

class BaseViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let myButton = UIBarButtonItem(title: "LogOut", style: .done, target: self, action: #selector(self.logoutTapped(_:)))
        self.navigationItem.rightBarButtonItem = myButton
    }

    @objc func logoutTapped(_ sender: UIBarButtonItem) {

        print("Logout clicked :) ")
    }
}

2- VC one

class ViewController: BaseViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

}

3- VC two

class ViewController2: BaseViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

}

Result

enter image description here

Upvotes: 1

Related Questions