5

I need a reference to the back button in the UINavigationBar or UINavigationItem. The Back button in the image below.

Navigation Bar

I am not customizing the button, thus

navigationItem.backBarButtonItem
navigationItem.leftBarButtonItem

these both are nil.

Is there any way to get a reference to the button without customizing it?

Reference:

Update: My comment might help to understand why I don't want to customize the back button. :)

2
  • Out of interest, why do you want a reference to it? Commented Aug 18, 2015 at 15:56
  • @Phoen1xUK I am using this github.com/szk-atmosphere/SAHistoryNavigationViewController pod in my project. But as you can see, the discoverability of this feature is very difficult. So I am using another pod github.com/teodorpatras/EasyTipView to show a tip about it. Now, this tip view needs a reference to this UIBarButtonItem to show a tip below it. Commented Aug 18, 2015 at 16:51

4 Answers 4

6

The Documentation says this about the backBarButtonItem:

When this item is the back item of the navigation bar—when it is the next item below the top item—it may be represented as a back button on the navigation bar. Use this property to specify the back button. The default value is a button displaying the navigation item’s title.

So the backBarButtonItem is always nil by default because it belongs to the previous view controller. The only way to get a non-nil reference is by customizing it.

If you just want to change the name, however, that can be done in the previous View Controller.

Sign up to request clarification or add additional context in comments.

1 Comment

This doesn't solve my issue. :( My use case - stackoverflow.com/questions/32076612/…
1

In reference to my use case - Ayush's comment

Till the time I get a concrete solution, I have created a dummy view below the navigation bar (below the back button) to show the tip from. Here is the code.

let v = UIView(frame: CGRectMake(0, 0, 50, 0))
view.addSubview(v)
let tipText = "Here it the back button"
EasyTipView.showAnimated(true,
  forView: v,
  withinSuperview: view,
  text:tipText,
  preferences: nil,
  delegate: self)

Comments

1

try out this one

let backItem = UIBarButtonItem(title: "Custom Text HERE", style: .Bordered, target: nil, action: nil)
navigationItem.backBarButtonItem = backItem

Comments

1

Try this it might help you.

 UINavigationItem *i = [self.navigationController.navigationBar.items firstObject];
    i.title = @"Hai";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.