简体   繁体   English

ARC-将uiview作为子视图添加到另一个uiview时使用强弱

[英]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. 我正在创建一个ipad应用程序,在其中我在其他UIViews和UIImageviews上添加了许多UIImageviews。 I am not sure whether to use strong or weak while adding UIImageviews as subviews . 我不确定将UIImageviews添加为子视图时是使用强还是弱。 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. 我创建了一个没有ARC的项目,现在我希望将其转换为ARC(由于“轻松的内存管理”),但是仍然不确定如何键入(弱/强)我的视图。

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. 如果您的父类是UIView的子类,那么您实际上是在向视图添加子视图。 So addSubview method add a strong reference to your view. 因此,addSubview方法为您的视图添加了强大的参考。 You can use weak reference. 您可以使用弱引用。

If your parent class is a subclass of UIViewController, you're not really adding subviews to a view. 如果您的父类是UIViewController的子类,那么您实际上并没有在视图中添加子视图。 So nothing add strong reference to your object. 因此,没有任何东西可以为您的对象添加强大的参考。 Use a strong reference. 使用有力的参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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