A diagram that gives you a clear picture of the hierarchical relationship between Uiviewcontroller,uinavigationcontroller and Uitabbarcontroller

Source: Internet
Author: User

When learning the multi-view controller, there was a problem that always bothered me, that is, to assign a value to the tag bar title.

In terms of the usual hierarchical relationship, a tabbed view contains a navigation view that sets the content view of the content we present in the Navigation view.

Uitabbarcontroller->uinavigationcontroller->uiviewcontroller

Both Uitabbarcontroller and Uinavigationcontroller inherit from Uiviewcontroller.

Uiviewcontrolleller's Tabbaritem

The last word in the details

The default value is a tab bar item that displays the View controller ' €™s title.

The tab bar element shows the title of the View controller by default.

Navigationitem, there's this same thing inside.


The default behavior is to create a navigation item that displays the View controller ' €™s title.

Create a navigation bar element by default displays the title of the View controller

1. Therefore activetylc.title = @ " Events "; Assigning values to the navigation bar and the tab bar can be traced.

2. How do I assign a value when our navigation bar title and tab bar headings are different?  


Uiviewcontroller is the parent of Uinavigationcontroller and Uitabbarcontroller.

Let's see how Navigationitem and Tabbaritem in Uiviewcontroller are explained.


The tab bar item is represents the view controller when added to a tab bar controller.


The tab bar element represents the Tab bar Element (parent tab Bar LABEL element) that the controller is added to the tab bar Controller

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

Navigation bar element represents the parent view controller's navigation bar element (parent navigation bar navigation Element)


According to the above-mentioned hierarchical relationship, at the top of the Uiviewcontroller

Write this:

self. Navigationitem. Title =@ " activity ";


self. Tabbaritem.  Title =@ " activity 123"; What will happen??

The result is: the navigation bar title shows "Active" and the tab bar is "empty".

If we assign a value to the tabbaritem of the navigation bar.

ActivetyNC.tabBarItem.title = @ " activity ";

The tab bar displays "active" normally.

Combine the navigation elements and tag elements in the above Uiviewcontroller. That makes sense.

Although


Both Uinavigationcontroller and Uitabbarcontroller inherit from Uiviewcontroller, and they all have tag elements and navigation element properties, but

For: Uiviewcontroller Navigationitem and Tabbaritem are not assigned, then NULL if the parent view is the navigation bar controller, Navigationitem is the navigationitem of the navigation bar Controller; If the parent class is Label Controller, the Tabbaritem is the Tabbaritem of the label controller.

One more thing: the navigation bar controller, which does not have a tab bar by default. I remember it wrong before. Here is a diagram that will give us a clearer picture of this.

This picture does not say that there is a tab bar behind the navigation bar, but that the navigation bar is further embedded in a tab bar. Carelessness kills people.


The navigation interface is further embedded inside a tab bar interface.



ACTIVETYLC


Navigationitem

A graph lets you clear the hierarchy of Uiviewcontroller,uinavigationcontroller and Uitabbarcontroller

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.