简体   繁体   English

子视图和超级视图之间的iOS参考关系

[英]iOS reference relationship between subview and superview

In the iOS documentation, it seems that subview has a strong reference to superview: 在iOS文档中,子视图似乎对超级视图有很强的引用:

@property(nonatomic, readonly) UIView *superview

The default for property is strong . 属性的默认值为strong As we all know, superview has a strong reference to subview, so is there a reference cycle between superview and subview? 众所周知,超级视图对子视图有很强的参考作用,那么在超级视图和子视图之间是否存在一个参考循环?

Yes, there is a reference cycle. 是的,有一个参考周期。 To get rid of a view, you have to call [theView removeFromSuperview] which breaks the cycle. 要摆脱一个视图,您必须调用[theView removeFromSuperview] ,这会中断循环。

No, the default is assign . 否,默认值为assign That's roughly the same as unsafe-unretained. 这与不安全,未保留的大致相同。

There won't be any reference cycle. 不会有任何参考周期。 When superview is deleted, it will delete all its children first before deleting itself. 删除超级视图后,它将先删除其所有子级,然后再删除自身。 If you just want to delete current view, you can do it. 如果您只想删除当前视图,则可以执行此操作。 Superview don't object. 监督不反对。

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

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