本篇文章主要介绍了" IBOutlet对象应该使用strong还是weak修饰",主要涉及到方面的内容,对于IOS开发感兴趣的同学可以参考一下:
ARC情况下,通常应该使用strong修饰,除非为了避免循环引用的情况。特别是在iOS6之后更应如此,使用weak修饰除了避免循环引用没有其他益处。And th...
- Before iOS 6, if you kept strong links to subviews of the controller's view around, if the view controller's main view got unloaded, those would hold onto the subviews as long as
the view controller is around.
- Since iOS 6, views are not unloaded anymore, but loaded once and then stick around as long as their controller is there. So strong properties won't matter. They also won't create strong reference
cycles, since they point down the strong reference graph.
That said, I am torn between using
@property (nonatomic, weak) IBOutlet UIButton *button;
and
@property (nonatomic) IBOutlet UIButton *button;
in iOS 6 and after:
Using weak
clearly
states that the controller doesn't want ownership of the button.
But omitting weak
doesn't
hurt in iOS 6 without view unloading, and is shorter. Some may point out that is also faster, but I have yet to encounter an app that is too slow because of weak
IBOutlet
s.
Not using weak
may
be perceived as an error.
Bottom line: Since iOS 6 we can't get this wrong anymore as long as we don't use view unloading. Time to party. ;)
参考链接:
Should
IBOutlets be strong or weak under ARC?
为什么 iOS 开发中,控件一般为 weak 而不是 strong?《招聘一个靠谱的 iOS》—参考答案(下)
IBOutlet连出来的视图属性为什么可以被设置成weak?
以上就介绍了 IBOutlet对象应该使用strong还是weak修饰,包括了方面的内容,希望对IOS开发有兴趣的朋友有所帮助。
本文网址链接:http://www.codes51.com/article/detail_3720741_2.html