开发者

The right way to manage subviews in a UIControl

开发者 https://www.devze.com 2023-01-01 00:14 出处:网络
(iPhone SDK 3.x:) I have a UIControl subclass that creates a different number of subviews depending on the length of an NSArray property.Please take my word for it that this needs to be a UIControl ra

(iPhone SDK 3.x:) I have a UIControl subclass that creates a different number of subviews depending on the length of an NSArray property. Please take my word for it that this needs to be a UIControl rather than a UIView.

Currently I implement subview management in dra开发者_运维问答wRect, beginning by removing all subviews and then creating the appropriate number based on the property. I don't think this is very good memory management and I'm not sure if drawRect is really the appropriate place to add subviews. Any thoughts on the best way to handle this pattern?

Thank you.


There is a method called layoutSubviews, and like the name already says, that method is thought to layout the subviews. You can call setNeedsLayout and the layoutSubviews method will be called (do not call layoutSubviews directly).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号