ENSwiftSideMenu
ENSwiftSideMenu copied to clipboard
Back Button in the Navigation Bar
I'm having trouble including a Back Button in the Navigation Bar. I've tried changing this to false: self.navigationItem.hidesBackButton = false But it didn't work. Any suggestions?
It's wrapped in a NavigationController, can you just drag a button out? Drop it, and should be there. Double check colors and if you have setup autolayouts, and change things, all view elements can get super out of wack. Just updates those constraints. Your button should show up.
@bcbucs13 did you have any luck implementing the back button?
I moved the menu to the top right rather than the top left and the back bottom started showing up
Hi, i found solution. i just change setContentViewController function in ENSideMenuNavigationController for pushing viewController into stack :
public func setContentViewController(contentViewController: UIViewController) {
self.sideMenu?.toggleMenu()
switch sideMenuAnimationType {
case .None:
self.viewControllers = [contentViewController]
break
default:
contentViewController.navigationItem.hidesBackButton = true
//self.setViewControllers([contentViewController], animated: true)
self.pushViewController(contentViewController, animated: true)
break
}
}
I'm new in IOS development, therefore i have question for @evnaz : Does that code above is correct way to add back button?
The setContentViewController method replaces the current view controller, from that controller you can push and pop other controllers in the navigation stack. That's why the code uses setViewControllers. If you push the controller you're adding that controller, meant to replace the whole stack, on top of the stack.
The only way, as far as I know, of making the back button show up is to place the side menu on the right, and of course the menu button on the right of the navigation bar. If you put any button on the left, the navigation bar can't show the back button, since a navigation bar can only have two buttons: one on the left, another in the right. If you leave the left one empty, the navigation bar uses that place for the back button automatically.
More over, in recent iOS releases the swipe gesture also performs the back operation, so putting the menu on the left side would also block that feature.
If you don't like the default behavior you can always make the navigation bar hidden and create your own navigation bar. Some apps, like Amazon for example, use that approach. I prefer to stick to the given behavior, even with its shortcomings, since the user has no need to learn how your app works: it works like the rest of the device apps.
I can insert and use Back button even in left-case menu, but I can not dismiss view. Why? it just does nothing
@IBAction func t(_ sender: Any) {
//toggleSideMenuView()
dismiss(animated: true, completion: nil)
}