ENSideSwiftMenu: how to use same Navigation Bar for all View Controllers - ios

I am using Evgeny Nazarov's Swift Side Menu for my iOS app and was wondering if anyone has used this same library and able to have the same Navigation Bar for every View Controller that is called from the menu.
I put a BarButtonItem that toggles the sliding menu on my Root View Controller. My problem is that only my Root View Controller shows this Toggle Button. But I would like to have that same Navigation Bar with the Toggle button on every View Controller that is accessible when clicking an option on the sliding menu.
Has anyone had an experience achieving this? Thanks!
UPDATE 1
This is what happens when I added a NavigationBar and BarButtonItem to the other ViewControllers that aren't the RootViewController. The new Navigation Bar ends up under the existing Navigation Bar from the Navigation Controller.
The screen on the left is the Root View Controller and the one on the right is the View Controller when I select the second item on the menu.
UPDATE 2: SOLVED
override func viewDidLoad() {
super.viewDidLoad()
let menuItem = UIBarButtonItem(image: UIImage(named: "icon_menu"), style: .Plain, target: self, action: "menuBarButtonItemClicked")
menuItem.tintColor = UIColor.whiteColor()
self.navigationItem.leftBarButtonItem = menuItem
}
func menuBarButtonItemClicked() {
toggleSideMenuView()
}

You need to put a UIBarButtonItem on the navigation bar in every view controller, not in the root view controller.

I too have used the same design for my app and I solved it this way:
View every sect "Show the Attribute Inspector -> Top bar" the voice "Translucent Navigation Bar", then drag the "Navigation Item" and then "Bar Button Item" in the position you want. Of course every button should have its code or references to the ViewController.
Let me know if you have solved.

Related

Hide bar button items swift

How can I hide my left bar button item?
In my storyboard I dragged a Navigation Bar onto my View Controller, then a Bar Button Item. Under certain conditions I want to hide the Bar Button Item.
None of this works:
override func viewDidLoad() {
self.navigationItem.leftBarButtonItem = nil
self.navigationItem.leftBarButtonItems = []
self.navigationItem.setLeftBarButtonItems([], animated: true)
}
I dragged a Navigation Bar onto my View Controller
Well, don't! There is a big difference between a navigation controller interface, where you set the navigationItem, and a loosey-goosey navigation bar just sitting there in the interface, which is what you have.
Embed your view controller in a UINavigationController and do things the right way. Then setting your navigationItem and its properties will work as expected.
You can't access to self.navigationItem.leftBarButtonItem because you manually drag navigationBar from storyboard. I would suggest to do the following instead:
add an IBOutlet of BarButtonItem (eg: barButton) that you created in storyboard
barButton.title = ""
barButton.isEnable = false
This will hide your BarButtonItem, and you can simply show it back later.

Navigation controller's toolbar not being hidden after enabling hide on tap?

I have a navigation controller where I have enabled hide on tap.It hides at first when I tap on the screen but when I tap again,the nav bar hides but the toolbar does not hide at all and it is obstructing my view. I have already tried settoolbarhidden and toolbar.hidden properties but it does not work.How do I solve this?
EDIT : I need to hide it only on this screen,I need the toolbar for other screens so thats why I have enabled shows toolbar.
EDIT 2 : Let me frame my question better.
When I enter the view controller :
Both navbar and toolbar hides because I have set it to hidden which is good
When I tap the screen :
Both navbar and toolbar shows because I have set it this way in the previous view controller.(If possible,Can I only show/hide the navigationbar on tap not the toolbar?
And lastly when I tap it again to hide both bars :
The navigation bar hides but the toolbar does not go away? This is my problem.
As Per your question you want to show tool bar on a particular viewController. View Controller viewWillAppear Function Hide ToolBar and viewDidDisappear show your tool bar it will show on other view controllers.
" Please check the navigation controller checkbox its disable or not.After that set this on your view controller before your profile view controller "
override func viewWillAppear(animated: Bool) {
self.navigationController?.toolbarHidden = true;
}
override func viewDidDisappear(animated: Bool) {
self.navigationController?.toolbarHidden = false;
}
I think it will resolve your issue.
I had the same problem.
The hideBarsOnTap only work if you placed smth in it. So if it is empty it will stay.
You could just put a blank imageView or Label there for example.
Or if you want it completely blank, your only option is to put a tabGestureRecognizer on your View!

Set custom nav back button with multiple navigation controllers

I have a tab bar controller that has 5 tabs, each with a navigation controller embedded in. There are times where I need to display a view controller from another tab.
I am overriding the stock back button text < BACK to just have it say <, which I do using
let backItem = UIBarButtonItem()
backItem.title = ""
navigationController?.navigationBar.tintColor = UIColor.whiteColor()
navigationItem.backBarButtonItem = backItem
However, when I load a view controller from a different tab bar (with a different navigation controller), I can't figure out how to remove the < BACK from the supplementary navigation controller so I can just display the button as <. Putting the above code in prepareForSegue: works with one nav controller, but not when there is a second one. Thanks a lot, any insight is greatly appreciated!
The back button that you see when a view controller is pushed onto the navigation controller's stack belongs, not to the pushed view controller, but to the previous view controller, the one that was showing before the push.
If that view controller says:
self.navigationItem.backBarButtonItem =
UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)
... then when a view controller is pushed on top of it, the back button will show no title.

iOS / Xcode - Navigation Item BackBarButtonItem title shows the one of the previous controller

i have 2 View Controllers connected by a segue within a Navigation Controller and I edited the back items titles in Interface Builder.
My problem is, that the BackBarButtonItem of the second controller shows the title of the first (and presenting) controller's BackBarButtonItem, no matter what I set for Back on the second controller's NavigationItem.
The only thing I've done is setting the leftBarButtonItem for the first Controller:
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Close", style: UIBarButtonItemStyle.Plain, target: self, action: "backTapped:")
Now all NavigationItems of presented Controllers show "Close". Does anyone have an idea, what's going on?
Thanks in advance
You have to configure desired back button item title on the view controller to which back will be performed, e.g. on previous one.

UINavigationItem BackButton shows the same as the UINavigationItem?

In my UINavigationController I push three of UITableViewController. In my second UITableViewController I set in viewDidLoad:
self.navigationItem.title = "controller2"
self.navigationItem.backBarButtonItem?.title = "c2"
Then I do the following. Starting at UITableViewController one push UITableViewController two and push UITableViewController three on the UINavigationController. When I reach UITableViewController three the back button displays controller2 instead of c2.
I did the same setup on the first UITableViewController and when I reach UITableViewController two the back button shows the correct title.
Why does the back button shows the wrong title?
As answered Here -
The title of the back button is either:
The title of the previous view controller
The name of the previous view controller's navigation item back button
If you are setting the back button for the current view controller's navigation item you are
not setting the button that get's displayed in the current view. You
are in fact setting the back button that will be used if you push
another view controller from it.
Or
You could init a new back button with title. Put this in the viewDidLoad() of view controller.
self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "c2", style: UIBarButtonItemStyle.Bordered, target: nil, action: nil)

Resources