IOS change Navigation's Back button

Source: Internet
Author: User

Two ways:

1, manually add Navigationitem LeftButton for each uiviewcontroller code

2, implement delegate for Uinavigationcontroller, change current and previous page Navigationitem.title at pop and push

The following are some of the basic methods of encapsulation, for reference:

+ (void) Navigationitem: (uinavigationitem*) Navigationitem

Settitle: (nsstring*) title;

+ (void) Navigationitem: (uinavigationitem*) Navigationitem

Setbackbutton: (nsstring*) title

AddTarget: (ID) target

Action: (SEL) Action;

+ (void) Navigationitem: (uinavigationitem*) Navigationitem

SetImage: (nsstring*) imagestring;

Helpless, had to study Uinavigationcontroller Class Reference go, in the "Updating the Navigation Bar" subsection, there is such a passage:

The bar button item on the left side of the navigation bar allows for navigation back to the previous view controller on t He navigation stack. The navigation controller updates the left side of the navigation bar as follows:

  • If The new top-level view controller has a and a custom left bar button item, this item is displayed. To specify a custom left bar button item, set the Leftbarbuttonitem property of the View controller ' s navigation item.

  • If The top-level view controller does not has a custom left bar button item, but the navigation item of the previous< /c0> View Controller has a valid item in its backbarbuttonitemproperty, the navigation bar displays that item.

  • If a custom Bar button item is not specified by either of the view controllers, a default back button was used and its titl  E is set to the value of the previous view Controller-that are, the view controller one level down The stack. (If There is a one view controller on the navigation stack, no Back button is displayed.)

I roughly explain that when you switch to the next view using Pushviewcontroller, the navigation controller changes the left button of the navigation bar in the following 3 order.

1. If b view has a custom left button (Leftbarbuttonitem), the custom button will be displayed;

2. If B does not have a custom button, but the Backbarbuttonitem property of a view has a customization, the customization is displayed;

3. If none of the first 2 are present, a back button is displayed by default, and the title of the Back button is the title of the A view.

According to this explanation, I put Uibarbuttonitem *backitem ... This code is placed before the Pushviewcontroller statement in the A view.

Ok problem solved, the title of the back button of B view is changed to backward.

eg

Uibarbuttonitem*backitem=[[uibarbuttonitemalloc]init];

[Email protected] "戻 る";

Self.navigationitem.backbarbuttonitem=backitem;

[Backitem release]

==============

New scheme:

Self.navigationcontroller.navigationbar.topitem.title=self.message;

Self.navigationcontroller.navigationbar.tintcolor=[uicolorblackcolor];

Uibarbuttonitem*backbutton = [[Uibarbuttonitemalloc] initwithtitle:@ "Fan hui" style: Uibarbuttonitemstyleborderedtarget:selfaction: @selector (Popviewcontroller)];

Self.navigationitem.leftbarbuttonitem= Backbutton;

Above transfer from: HTTP://HI.BAIDU.COM/MYYUCHONG/ITEM/1E6DB306C5D34DE1359902A1

PS: In the third case, the auto-created return button only takes the title value of a view, the other properties are not copied, it seems to change the color and other properties have to customize a return button AH

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.