开发者

NIB, setValue:forKey and retain (iOS)

I know some mechanism of outlet connection when loading NIB, but I am not sure. So I'm asking some questions to ensure my knowledge. I assumed these things all true, but It's hard to find mention about these on reference documentation. Please point wrong and right things.

I have an IBOutlet defined like this: (Of course it's not recommended way)

@implementation
{
    IBOutlet id var1;
}
@end
  1. NIB loader (alloc | retain) & autorelease all top-level objects. So it will be dealloc on runloop turn ends without additional retain.
  2. Connecting IBOutlets are done with KVC.
  3. KVC uses accessor method primarily.
  4. KVC uses setValue:forKey secondarily. And the IBOutlet will be handled by this method because there's no declared property or access method.
  5. setValue:forKey retains the new value object.
  6. setValue:forKey releases the old value object.
  7. So top-level object connected t开发者_如何学编程o the IBOutlet will be retained once. So I have to release it to dealloc. This is why I must release objects connected to IBOutlet on dealloc method.
  8. If the object connected another IBOutlet like the IBOutlet, it should be released once more to be dealloc.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜