ENSwiftSideMenu icon indicating copy to clipboard operation
ENSwiftSideMenu copied to clipboard

Back Button in the Navigation Bar

Open bcbucs13 opened this issue 10 years ago • 6 comments

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?

bcbucs13 avatar Feb 18 '15 00:02 bcbucs13

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.

ejpusa-zz avatar Mar 04 '15 03:03 ejpusa-zz

@bcbucs13 did you have any luck implementing the back button?

FrancisBaileyH avatar May 02 '15 03:05 FrancisBaileyH

I moved the menu to the top right rather than the top left and the back bottom started showing up

bcbucs13 avatar May 08 '15 19:05 bcbucs13

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?

bakomchik avatar May 17 '15 16:05 bakomchik

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.

ncerezo avatar Jun 04 '15 09:06 ncerezo

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)
}

djdance avatar Jan 23 '17 18:01 djdance