简体   繁体   中英

ARC - use strong or weak when adding a uiview as subview to another uiview

I am creating an ipad app where I add many UIImageviews over other UIViews and UIImageviews. I am not sure whether to use strong or weak while adding UIImageviews as subviews . I have created a project without ARC and now I am looking forward to convert it to ARC(because of "easy memory management") but still not sure about how should I type(weak/strong) my views.

Are you really trying to add subviews to a view or to add reference to subviews in a view controller?

If your parent class is a subclass of UIView, you're really adding subviews to a view. So addSubview method add a strong reference to your view. You can use weak reference.

If your parent class is a subclass of UIViewController, you're not really adding subviews to a view. So nothing add strong reference to your object. Use a strong reference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM