2

I'm working on an app where a viewController is embebed in navigationBar and this navigationBar is embebed in TabBarViewController.

In my app I have 2 different tabs (for the moment), one tab is the "Activity view". This is a viewController with a tableView where list activities. Every cell will show the same view controller showing detail activity when it's touched.

My problem is that not showing navigationItem with buttons.

I'm trying the solution of: Bar button item not shown in navigationBar , because my problem is very similar but it did not work.

some screenshots of storyboard and app running: storyboard App running without buttons

I'm trying programmatically add buttons but no results:

var logoutButton: UIBarButtonItem!
var filterButton: UIBarButtonItem!


//MARK: - Lyfe cycle
override func viewDidLoad() {
super.viewDidLoad()

let logoutImage = UIImage(named: "logout-24")
let filterImage = UIImage(named: "filterOutline-24")

logoutButton = UIBarButtonItem(image: logoutImage, style: .Plain, target: self, action: "logoutAction:")
filterButton = UIBarButtonItem(image: filterImage, style: .Plain, target: self, action: "filterAction:")
navigationItem.rightBarButtonItems = [filterButton, logoutButton]
Community
  • 1
  • 1
Rodrigo A
  • 21
  • 4
  • I tried several ways to work the SPLITVIEW as a side menu but did not succeed. So I looked for other ways to perform the desired result. So I found a side Menu [stackoverflow](http://stackoverflow.com/questions/31930585/drawer-like-google-material-design-for-ios) the github [github](https://github.com/ykyouhei/KYDrawerController) which soon time got the expected result. Including tabbar and their respective sailings. Thank you anyway. – Rodrigo A Apr 05 '16 at 01:56

3 Answers3

2

For tabar application we should add like this,

 let logoutButton = UIBarButtonItem(image: UIImage(named: "ic_logout"), style: .plain, target: self, action:#selector(logoutButtonTapped))    
 self.tabBarController?.navigationItem.leftBarButtonItem = logoutButton

 let nightModeButton = UIBarButtonItem(image: UIImage(named: "ic_night_mode_off"), style: .plain, target: self, action:#selector(nightModeButoonTapped))
 self.tabBarController?.navigationItem.rightBarButtonItem  = nightModeButton
0

Check your image. I don't see any problem with your code. Or you can try add just title like below

logoutButton = UIBarButtonItem(title: "Log out", style: .Plain, target: self, action:Selector("logoutAction:"))
filterButton = UIBarButtonItem(title: "Filter", style: .Plain, target: self, action: Selector("filterAction:"))

If button bar show. I sure that problem is your image.

vien vu
  • 4,277
  • 2
  • 17
  • 30
  • thanks but it doesn't work. The button is still not showing. I think it has to do with the navigationItem not showing, but I don't know how to fix it... – Rodrigo A Mar 31 '16 at 15:17
  • the previous version (without tabbar) show the buttons, but when I add the tabBar this buttons not showing... [link](http://i.imgur.com/1QymvGs.png) , [link](http://i.imgur.com/dDThJ1s.png). I need add tabBar for other views... :/ – Rodrigo A Mar 31 '16 at 15:45
  • can you check your navigationItem it nil or not? – vien vu Mar 31 '16 at 15:53
  • interesting... how I can check my navigationItem it nil? part of my viewDidLoad: `override func viewDidLoad() { super.viewDidLoad() activityIndicator.hidesWhenStopped = true if let contract = detailContract { navigationItem.title = contract.Name loadActivities(contract) } } ` – Rodrigo A Mar 31 '16 at 16:00
  • you print print(navigationItem) in your viewdidload. – vien vu Mar 31 '16 at 16:03
  • my print was: – Rodrigo A Mar 31 '16 at 17:09
  • I forgot to add a segue in splitView: [new Storyboard](http://i.imgur.com/e6Bhxyd.png) . Now appears buttons :) But no back button [app running](http://i.imgur.com/sdBsusu.png)....how add back button to masterViewController (from SplitViewController...) – Rodrigo A Mar 31 '16 at 18:03
0

I also faced the similar problem, later I found that set up your navigation bar in tab bar controller itself, no need to do in view controllers

let profilePutton = UIButton(type: .custom)
profilePutton.setTitle("Profile", for: .normal)
profilePutton.frame = CGRect(x: 0.0, y: 0.0, width: 30.0, height: 30.0)
profilePutton.addTarget(self, action: #selector(openProfilePage), for: .touchUpInside)
navigationItem.rightBarButtonItem = UIBarButtonItem(customView: profilePutton)