How to set the title and action of Backbarbuttonitem

Source: Internet
Author: User

  1. WhyDoes Self.navigationItem.backBarButtonItem have any effect on the Backbarbuttonitem displayed on the navigation bar within Uiviewcontroller?

First, we need to know.

Backbarbuttonitem (where the Text property appears to fail if it is too long)

Leftbarbuttonitem

Rightbarbuttonitem

They are all part of the Uinavigationitem, all shown on the Navigationbar, belong to the Uibarbuttonitem class

Backbarbuttonitem and the other two brothers are different.

For example, there are currently acontroller ready to Push to Bcontroller, set Backbarbuttonitem title and image to be set within Acontroller, set before calling Acontroller Push:b , AController.navigationItem.backBarButtonItem = ....

While the other two brothers are in the Bcontroller viewdidload after the set can be.

Description of the Backbarbuttonitem

Discussion

When this navigation item is immediately below the top item on the stack, the navigation controller derives the back Butto N for the navigation bar from this navigation item. When nil the "is", the navigation item uses the value in the It property to title create a appropriate back button . If you want to specify a custom image or title for the Back button, you can assign a custom bar button item (with your Cus Tom Title or image) to the property instead. When configuring your Bar button item, does not assign a custom view to it; The navigation item ignores the custom views on the back bar button anyway.

Explains that Backbarbuttonitem can only customize the image and title, and cannot override the target or action, and the system ignores other related settings.

If you simply need to rewrite the action to do some other work, you need to customize a leftbarbuttonitem because the system-defined Leftbarbuttonitem has a higher priority than Backbarbuttonitem, When Leftbarbuttonitem is present, the Backbarbuttonitem is automatically ignored and the purpose of rewriting the backbarbuttonitem is achieved.

2. The difference of Backbarbuttonitem under each object

For these 3 brothers, they can be found under 3 classes.

For example, in a uiviewcontroller, you can find them by typing in the following methods. (With Leftbarbuttonitem | Rightbarbuttonitem)

Self.navigationItem.backBarButtonItem

Self.navigationController.navigationItem.backBarButtonItem

Self.navigationController.navigationBar.backItem.backBarButtonItem

For example, in Acontroller->bcontroller, The Self.navigationItem.backBarButtonItem was set in a, and it was experimentally found that the Backbarbuttonitem was Bcontroller Self.navigationController.navigationBar . Backitem.backbarbuttonitem.

Uiviewcontroller Property Navigationitem is the property managed by the current Uinavigationbar--[uinavigationbar appearance]

@property (Nonatomic, ReadOnly, retain)uinavigationitem *navigationitem

The navigation item used to represent, the view controller in a parent ' s navigation bar. (read-only)


Self.navigationController.navigationItem.backBarButtonItem

Is the uinavigationbar of the parent that represents the current navigationcontroller, and generally does not have such a nesting.

How to set the title and action of Backbarbuttonitem

Related Article

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.