简体   繁体   English

为什么UIWebViewDelegate分配而不是弱?

[英]why is UIWebViewDelegate assign instead of weak?

Normally all delegates throughout the UIKit/Foundation frameworks are weak except UIWebView. 通常,除了UIWebView之外,整个UIKit / Foundation框架中的所有代理都很弱。

UIWebView's delegate UIWebView的委托

@property(nonatomic, assign) id< UIWebViewDelegate > delegate;

I am interested because this has caused a crash several time in my application when you forgot to nil out delegate while dismissing the UIWebView's ViewController. 我感兴趣,因为当你在解雇UIWebView的ViewController时忘记取消委托时,这在我的应用程序中造成了几次崩溃。 Normally you don't expect something like this, so there might be specific reason why this isn't set to weak by default. 通常你不会期望这样的东西,所以可能有一个特定的原因,为什么默认情况下这不会设置为弱。

Suppose if the UIWebViewDelegate defined as WEAK then in ARC it will automatically nil the reference of delegate. 假设如果在UIWebViewDelegate ARC定义为弱,然后它会自动代表参考。 So UIWebViewDelegate marked as ASSIGN because if the class is not compiled with ARC then we have to take care of set it as nil. 因此,UIWebViewDelegate标记为ASSIGN,因为如果该类未使用ARC编译,那么我们必须将其设置为nil。

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

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