# Navigation item does not change the title

**URL:** <https://forums.kodeco.com/t/navigation-item-does-not-change-the-title/14862>\
**Category:** iOS\
**Created:** [May 15, 2016, 10:45am UTC](https://forums.kodeco.com/t/navigation-item-does-not-change-the-title/14862 "2016-05-15T10:45:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![antonio\_k](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/antonio_k/32/81494_2.png) [@antonio\_k](https://forums.kodeco.com/u/antonio_k)\
**Post date:** [May 15, 2016, 10:45am UTC](https://forums.kodeco.com/t/navigation-item-does-not-change-the-title/14862/1 "2016-05-15T10:45:36Z")

</div>

I have simple view controller that is embedded in navigation controller, also I create by drag a’drop an bar button item to the right, connected it as action to the code and named it edit. So what I want it, if click on the button it should verify the title and change it if needed, here is the code:

```
class MyClass: ViewController {

  @IBAction func editButtonPressed(sender: AnyObject) {

   if (self.navigationItem.rightBarButtonItem?.title == "Edit") {
     self.navigationItem.rightBarButtonItem?.title == "Done"
   } else {
     self.navigationItem.rightBarButtonItem?.title = "Edit" 
  }

```

but its doesn’t work. Thank ever for the advances

---

<div class="post-metadata">

**Author:** ![marciokoko](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/marciokoko/32/32922_2.png) [@marciokoko](https://forums.kodeco.com/u/marciokoko)\
**Post date:** [May 19, 2016, 10:03pm UTC](https://forums.kodeco.com/t/navigation-item-does-not-change-the-title/14862/2 "2016-05-19T22:03:28Z")

</div>

> [@antonio\_k](#):
>
> @IBAction func editButtonPressed(sender: AnyObject) {
> 
> if (self.navigationItem.rightBarButtonItem?.title == “Edit”) {  
> self.navigationItem.rightBarButtonItem?.title == “Done”  
> } else {  
> self.navigationItem.rightBarButtonItem?.title = “Edit”  
> }

Did you connect the rightbarbuttonitem you dragged to the declaration of it in code?

---

<div class="post-metadata">

**Author:** ![antonio\_k](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/antonio_k/32/81494_2.png) [@antonio\_k](https://forums.kodeco.com/u/antonio_k)\
**Post date:** [May 21, 2016, 7:44am UTC](https://forums.kodeco.com/t/navigation-item-does-not-change-the-title/14862/3 "2016-05-21T07:44:28Z")

</div>

Hallo marciokoko,  
I found already my error, in the third line, I used equals operator rather then assign operator,  
with this line it works neat:

> ```
> if (self.navigationItem.rightBarButtonItem?.title == "Edit") {
> self.navigationItem.rightBarButtonItem?.title = "Done"
> } ...
> 
> ```
