I need a reference to the back button in the UINavigationBar
or UINavigationItem
. The Back
button in the image below.
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. :)
A UINavigationBar object is a bar, typically displayed at the top of the window, containing buttons for navigating within a hierarchy of screens. The primary components are a left (back) button, a center title, and an optional right button.
The backBarButtonItem property of a navigation item reflects the Back button you want to display when the current view controller is just below the topmost view controller. The Back button doesn’t appear when the current view controller is topmost. When specifying buttons for a navigation item, you must use UIBarButtonItem objects.
The managing UINavigationController object uses the navigation items of the topmost two view controllers to populate the navigation bar with content. A navigation item always reflects information about its associated view controller. The navigation item must provide a title to display when the view controller is topmost on the navigation stack.
When configuring your bar button item, do not assign a custom view to it; the navigation item ignores custom views in the back bar button anyway. It’s very important to read the first sentence carefully, “When this navigation item is immediately below the top item in the stack… .”
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With