Notes about addSubView-a big loss occurred today, and a big loss occurred in addsubview.

Source: Internet
Author: User

Notes about addSubView-a big loss occurred today, and a big loss occurred in addsubview.

AddSubview:

Adds a view to the end of the specified er's list of subviews.

Add a View to the subview list of the receiver.

 

-(Void) addSubview :( UIView *) view

Parameters

View

The view to be added. This view is retained by the specified er. After being added, this view appears on top of any other subviews.

The view parameter indicates the added view, which is retained by its receiver once (that is, the reference count + 1 ). After the addition, the view will appear on the other sub-views of the receiver.

Ps: you can find the answer to the hierarchy problem of the subview from the Data Structure Stored in these subviews. Each view has an array attribute, subviews, this is the reference of the stored child view. The order of this array represents the order in which each sub-view is added. Index = 0 is the first to be added, and so on. Therefore, a view with a higher index value is not easily overwritten.

Discussion

This method retains view and sets its next responder to the caller, which is its new superview.

Translation:This method retests the view once and sets the next responder to the parent view, that is, its new parent view.

Ps: As mentioned in removeFromSuperview, direct view operations usually involve two aspects: one is the data structure of the view and the other is the response chain. Of course, addsubview is no exception.

Views can have only one superview. If view already has a superview and that view is not the creator, this method removes the previous superview before making the Creator er its new superview.

Each view can have only one parent view. If the current operation view has another parent view,The addsubview operation will first remove it from the previous parent view (including the responder chain) and then add it to the new parent view.


Conclusion: When two views with the same memory and one View with addSubview are added, the two views are not superimposed!

 

Availability

  • Available in iOS 2.0 and later.

See Also

    • -InsertSubview: atIndex:
    • -InsertSubview: aboveSubview:
    • -InsertSubview: belowSubview:
    • -ExchangeSubviewAtIndex: withSubviewAtIndex:

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.