What happens if I don't retain IBOutlet?

后端 未结 6 1493
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 16:13

If I do this:

@interface RegisterController : UIViewController 
{
    IBOutlet UITextField *usernameField;
}

ins

6条回答
  •  死守一世寂寞
    2020-11-29 16:53

    Declaring something IBOutlet, from a memory management standpoint, does nothing (IBOutlet is literally #defined as nothing). The only reason to include IBOutlet in the declaration is if you intend to connect it in Interface Builder (that's what the IBOutlet declaration is for, a hint to IB).

    Now, the only reason to make an @property for an instance variable is if you intend to assign them programatically. If you don't (that is, you're only setting up your UI in IB), it doesn't matter whether you make a property or not. No reason to, IMO.

    Back to your question. If you're only setting this ivar (usernameField) up in IB, don't bother with the property, it won't affect anything. If you DO make a property for usernameField (because you're programatically creating it), definitely do make a property for it, and absolutely DO make the property retain if so.

提交回复
热议问题