Correct understanding of navgation's backitem

Source: Internet
Author: User

Assume that the controller from view a enters View B controller (Self refers to acontroller, bcontroller refers to B)

Uinavigationcontroller class reference found and usedSwitch pushviewcontroller to the next viewThe navigation controller changes the buttons on the left of the navigation bar in the following order.
1. If View B has a custom left button (leftbarbuttonitem), the Custom button is displayed, and the rectangle is not pointed;
2. If B does not have a custom button, but the backbarbuttonitem attribute of View A has a custom item, this custom item is displayed,The style is sharp;
3. If none of the first two items exist, a back button is displayed by default. The title of the back button is the title of view. The button style is sharp.

According to this explanation, if you want to modify the backitem, the modified Code should be placed before the pushviewcontroller Statement of view.

Uibarbuttonitem * backitem = [[uibarbuttonitem alloc] initwithtitle: @ "back" style: uibarbuttonitemstylebordered target: Nil action: Nil]; [self. navigationitem setbackbarbuttonitem: backitem]; // modify navigationitem [backitem release] of a; [self. navigationcontroller pushviewcontroller: bcontroller animated: Yes]; // You must modify it before pushing.

Let's discuss another question here. have you noticed that when we use or modify navgationbar, It is self. navigationcontroller. navigationbar, and the item is modified using self. navigationitem.

What does this problem mean?

That is, navgationcontroller is unique in a hierarchical view management structure and manages the view stack. That is to say, all self. navigationcontroller attributes, such as self. navigationcontroller. navigationbar. This modification or use is global for the entire view stack, and then it is specific to a control, that is, navigationbar is unique.
Similarly, when self. navigationitem is used, it means that a property of self is modified, which means that navigationitem is only an attribute of the current view. Therefore, each view has its own navigationitem. This is also true by printing logs in xcode4.4. I just don't know if all the versions are uniform.

The log is as follows:

Main: <uinavigationitem: 0x6b912b0>
Main: <uinavigationcontroller: 0x6b82630>
Main: <uinavigationbar: 0x6b90620; frame = (0 20; 320 44); autoresize = W; layer = <calayer: 0x6b90710>
Second: <uinavigationitem: 0xde6f470>
Second: <uinavigationcontroller: 0x6b82630>
Second: <uinavigationbar: 0x6b90620; frame = (0 20; 320 44); autoresize = W; layer = <calayer: 0x6b90710>

Click return and jump to second again. A new navigationitem is generated with the new controller.
Second: <uinavigationitem: 0x6b92dd0>
Second: <uinavigationcontroller: 0x6b82630>
Second: <uinavigationbar: 0x6b90620; frame = (0 20; 320 44); autoresize = W; layer = <calayer: 0x6b90710>

Navigationitem is inherited from nsobect and serves as a container. It can be used to display the title, left and right buttons, and so on in navgationbar.

There are still some reasoning about buttonitem, so let's think for ourselves. Leave some space for everyone. Roar ~~

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: 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.