Hi Alex and Alex ;-),

I think you misunderstood the meaning of the back button field in interface 
builder. I know it’s easy to get it wrong, because I did so as well. Let’s see:

> I have a navigation item inside a view, which is a couple levels inside a 
> navigation controller's stack. I can change the title of the navigation item 
> through the "title" attribute (in IB) with no trouble. However, when I 
> entered some text for the "back button" title, Xcode shows that text in the 
> Attributes Inspector, but it isn't used in my app. Instead of „cancel" as I 
> wrote, I get the standard "[previous view name] back" text instead. 

Here it is important to specify which navigation items you are talking about. 
Let’s look at the simplest example: Having two view controllers in a navigation 
controller. Let’s say view controller A is the root view controller and view 
controller B is the detail view controller that is sometimes pushed onto A.

Now I assume you are setting the title of the navigation item of B to configure 
the displayed title when the detail view is shown. I also assume that you set 
the back button title on the same navigation item, so the navigation item of B. 
However, this is the wrong navigation item to configure the back button that is 
displayed together with B. You need to set the title on the back button of 
navigation item A, the previous view controller.

Why is that?
The back button field in Interface Builder’s navigation item refers to the 
title of the back button pointing back to the OWNING view controller. So, it 
specifies the title that should be used in the navigation view of a view 
controller that is displayed on top of this view controller to indicate what 
view controller is going to be shown when the back button is pressed.

There is an important difference between a navigation item’s 
„leftBarButtonItem“ and „backBarButtonItem“. The 
„self.navigationItem.leftBarButtonItem“ refers to the button on the left of the 
navigation bar displayed above the current view controller. The 
„backBarButtonItem“ specifies a bar button item to use when the corresponding 
view controller is the PREVIOUS view controller and not currently displayed. Or 
as the documentation puts it:

> backBarButtonItem
> The bar button item to use when a back button is needed on the navigation bar.
> When this navigation item is immediately below the top item in the stack, the 
> navigation controller derives the back button for the navigation bar from 
> this navigation item. When this property is nil, the navigation item uses the 
> value in its title property to create an appropriate back button.
Source: 
https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UINavigationItem_Class/index.html#//apple_ref/occ/instp/UINavigationItem/backBarButtonItem



TL;DR: You need to set the back button title by setting it in the „back button“ 
field of the root view controller (or otherwise preceding view controller). 
If you do not want to set it there and always want to use a specific back 
button title, no matter what the previous view controller is (hint: you 
probably shouldn’t), you need to do it in code.
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/xcode-users/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to