Search code examples
swiftrightbarbuttonitem

Bar button item not working


I have read the other posts here and trying all the things they say, but still is not working for me, I really need to add a right bar button item, I have tried in code (doesn't work for me) and I found something that might help me but, I don't know where is it in the interface of xCode, here is the image I found: image Can someone tell me how to make this work please?

Here is my storyboard at the left (the color changes) and the simulator at the right, and as you can see in the storyboard it shows my barButtonItem but when I run it it doesn't shows. myProject


Solution

  • It seems like you are not following the correct steps to add the right bar button. It can be easily done through storyboard itself and it doesn't requires to modify any property of the navigation bar. Also looking on the images of the storyboard and simulator you shared shows some inconsistency, it would be more clear if you can elaborate on the steps you followed to add the right bar button item, how are you adding it to the navigation bar and how are you connecting your view controller to the presenting View controller.

    The usual Steps I follow is :

    1. There should be a Navigation controller attached to the root view controller.
    2. If you need to show UIBarButtonItem on this Root View Controller you can simple drag to its right position.
    3. If you need to show it on some other view controller that will be pushed, then there are two scenarios:
      • The Presented View Controller is connected directly to the Presenting View Controller through segue inheriting the navigation bar from the Presenting View Controller. In this scenario you have the follow the same procedure as in step 2.
      • The Presented View Controller is not connected directly to the Presenting View Controller and you are pushing it through code. In this case you have add a navigation item first and then you have to place the right bar button on it.

    I hope this would work for you :)