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: