View Hierarchy IOS

Source: Internet
Author: User

The view hierarchy is used to illustrate the relationship between the view in window.

View hierarchy can be thought of as a flipped tree structure, while window is the topmost node (root node) of the tree. Below the tree is the relationship between father and son view. Visually, the view hierarchy is a closed structure, that is, a view contains one or more view, and the window contains all the view.



View hierarchy is also an important part of responder chain, and when we need to render the contents of a window, the framework of the application uses it to detect the layers of views, to determine the parts that need to be rendered, so as to avoid doing some useless work, This is crucial.

Next look at the definition relationship of the three properties of view in view hierarchy

Parent view of 1.superview,view

Child view of 2.subviews,view

3.window, window with view

There is a difference between iOS and Mac about the third window property.

In iOS, window is a view, but not in a Mac.

In Mac, window has a separate contentview, and all sub-views are included in the Contentview.

In iOS, window plays its own role as a contentview, so the child views are all included in the window.

Such as



At the time of development, sometimes you will encounter

1.ios attempt to present whose view isn't in the window hierarchy

2.warning:attempt to present on whose view isn't in the window hierarchy!

such as such a hint, as long as the inside hint window hierarchy, are the view hierarchy understanding is not in place caused.

The above problems are in a controller's view has not been added to the window time and take present another controller, which is equivalent to the building, 2 floor has not finished, directly to cover the 3 floor, so certainly not.

The most straightforward solution to the problem above is to call present in the controller's viewdidappear. This ensures that the hierarchical structure of the view hierarchy is not chaotic.

View Hierarchy IOS

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.