Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot add Bar Button Item to Navigation Controller in Xcode

I am building a todo list app to get more practice with tableViews and delegates. I have embedded my primary tableViewController in a Navigation Controller and I have created two additional view controllers, one for adding a task and one fore editing a task. When I attempt to add a bar button item to one of the additional view controllers (done, trash, etc), Xcode is placing the item in a tab bar along the bottom of the screen and when I run the app, those items are not visible. I have changed the type of device I am working on, relaunched Xcode entirely, and I cannot figure out why this is happening. I have added a screenshot below and here is a link to the repo. Any ideas why this is happening?

enter image description here

like image 442
Andrew Tuzson Avatar asked Dec 02 '22 10:12

Andrew Tuzson


2 Answers

first you need to add Navigation Item in Navigation Bar. then add UIBarButton in Navigation Item.

Navigation Item

full example

like image 96
Mohammadalijf Avatar answered Dec 04 '22 04:12

Mohammadalijf


Programatically you can add as:

        let shareBarButtonItem = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(self.shareClass))

        let downloadBarButtonItem = UIBarButtonItem(image: UIImage(string: UIImage(named: "your_image_name")), style: .plain, target: self, action: #selector(self.downloadClass))

        self.navigationItem.setRightBarButtonItems([shareBarButtonItem, downloadBarButtonItem], animated: true)
like image 21
Krishna Kirana Avatar answered Dec 04 '22 05:12

Krishna Kirana