0

I have a main view controller with a tableview and a detail view controller to display details about the selected item. I have a nav bar that inserts a back button when user segues to detail screen. On this detail screen, I have a container view that can show other view controllers on the bottom half of the screen. When user brings up a subview, I want to replace the standard back button with my custom button that just resigns the subview, not going back to main view controller. Once the subview is gone, the back button should revert back to stock back button that will go back to main view controller when pressed.

My issue is that I'm having trouble making the back buttons appear the same so user doesn't know I'm using different buttons to achieve these different things. What is the best way to do this? I can't get the text to match up, is an image the better way to go?

Currently in prepareForSegue in main view controller:

// setting nav button text to "<" which is default when no text
      let backItem = UIBarButtonItem()
      backItem.title = ""
      navigationController?.navigationBar.tintColor = UIColor.whiteColor()
      navigationItem.backBarButtonItem = backItem

Currently in detail view controller:

func createCustomBackButton() {

      self.navigationItem.hidesBackButton = true

      let customFont = UIFont(name: "HelveticaNeue", size: 30.0)!
      UIBarButtonItem.appearance().setTitleTextAttributes([NSFontAttributeName: customFont], forState: UIControlState.Normal)

      customBackButton = UIBarButtonItem(title: "<", style: .Plain, target: self, action: "back:")
      self.navigationItem.leftBarButtonItem = customBackButton
   }

Any help is greatly appreciated, thanks in advance!!

4
  • Maybe screenshot for detail vc will help. Commented Feb 3, 2016 at 0:59
  • Thanks for your response. It won't really help showing anything. Basically the detail view has some general things that user can tap which brings up the subview with more detail. When the subview appears, the custom back button appears which resigns the subview. Commented Feb 3, 2016 at 1:11
  • I don't think there's a way to get straight access to the default system back button, so instead you might want to make a custom back button your base VC and use the same one on your detail VC so the user won't know the difference. Commented Feb 3, 2016 at 1:43
  • You haven't pushed a view. You've shown something in the same view controller. Wouldn't this be more of a "Done" paradigm to hide the subview, since there is nothing that has been pushed, or needs to be popped? And if you hijack the Back button, what will the experience be when the user thinks they can return from the detail to the main view? (The user could still edge-swipe to move back... wouldn't it be inconsistent if they could swipe but not tap Back?) Commented Feb 3, 2016 at 1:49

1 Answer 1

1

so the short answer is you have to create your own back button

   self.navigationItem.hidesBackButton = true;
  self.navigationItem.leftBarButtonItem = //your custom bar button item

alternatively you can piggy back on the default iOS button with out the over head

by setting the back title to "" and setting the back indicator image

    self.backIndicatorImage = backButtonIcon.image
    self.backIndicatorTransitionMaskImage = backButtonIcon.image
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.