Search code examples
swiftswift2uitabbarcontrolleruinavigationitem

Swift Tabbar Controller Bar button item


I have a 3 tab in my app.(First one is People, Second is Calls and Third is Chats)

When I add a left or right button item in chats tab, then I can see the buttons in other tabs. (I used show segue when creating tabs)

how can I solve my problem?

This is my code:

self.tabBarController!.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .Compose, target: self, action: #selector(addNew))

self.tabBarController!.navigationItem.leftBarButtonItem = self.editButtonItem()

Solution

  • You are setting the TabBarController's navigation items. You should set the view controller's.

    self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .Compose, target: self, action: #selector(addNew))
    self.navigationItem.leftBarButtonItem = self.editButtonItem()