Is it possible to add a UIBarButtonItem to the pushed right view?

Hello friends

My app has a Navigation Controller, after I pushed a view to the most right view, makes sense to add a BarButtonItem to insert a calendar but I cannot find a way to inserted there since I does not allow me on storyboard.The left view has a Navigation Item Bar but the most right one does not! Only a Back button that is added automatically.

I had go to Apple documentation trying to find an anser but I can´t find info on how can that be done.

I would like to add a BarButtonItem to insert a calendar Button for the user be able to choose a date.

Here is a picture on what I'm trying to acomplish

https://ibb.co/bZzUid


Thanks all for your time

Hugo

Accepted Reply

You can add a Bar Button Item: control-drag to the right of the navigation bar (you may have to move a little bit around until a blue rectangle appears).


You can then connect an IBAction


    @IBAction func testNavItem(_ sender: UIBarButtonItem) {
        print("Nav Item pressed")
    }



If you want to hide, but not remove, on certain condition :


Create an IBOutlet in the controller


    @IBOutlet weak var rightNavItem: UIBarButtonItem!


In viewDidLoad


if needToHide {     // Your condition
        rightNavItem.isEnabled = false
        rightNavItem.tintColor = UIColor.clear
} else {
        rightNavItem.isEnabled = true
        rightNavItem.tintColor = .blue      // Restore it
}

Replies

You can add a Bar Button Item: control-drag to the right of the navigation bar (you may have to move a little bit around until a blue rectangle appears).


You can then connect an IBAction


    @IBAction func testNavItem(_ sender: UIBarButtonItem) {
        print("Nav Item pressed")
    }



If you want to hide, but not remove, on certain condition :


Create an IBOutlet in the controller


    @IBOutlet weak var rightNavItem: UIBarButtonItem!


In viewDidLoad


if needToHide {     // Your condition
        rightNavItem.isEnabled = false
        rightNavItem.tintColor = UIColor.clear
} else {
        rightNavItem.isEnabled = true
        rightNavItem.tintColor = .blue      // Restore it
}