Difference between addSubview: and insertSubview:atIndex:?
cocoa-touch, iphone, objective-c
Solution
Both add a view to the receiver as a subview, which causes the view to be displayed if the receiver is displayed and positioned relative to the receiver.
But,
- `addSubview:` adds your view to the end of the subview list, which places it on top of the other subviews when drawing.
- `insertSubview:atIndex:` adds your view at a particular position in the list, which places it above the subviews that come before it in the list, and below the subviews that come afterward.
`[parentView addSubview:childView]` is the same as `[parentView insertSubview:childView atIndex:[[parentView subviews] count]]`.
Everything you need to know is here.
Problem
When adding subviews to a `UIView`, what's the difference between the methods `addView:` and `insertView:atIndex:`?