Does an IBOutlet needs to be a property & synthesized?

前端 未结 4 2510
隐瞒了意图╮
隐瞒了意图╮ 2020-11-29 16:37

In most examples I see the following setup of IBOutlets:



(Example A)

FooController.h:

@interface FooController : UIViewController {
    UILabel *fooLabel         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-29 17:15

    The end result is exactly the same, but you have to keep a few things in mind:

    • When using instance fields as outlets, you should NOT release them in dealloc.

    • When using properties that have the (retain) attribute, you have to release the property in dealloc (using self.property=nil or by releasing the backing variable). This makes it a lot more transparent as to what's going on.

    Actually it all comes down to the same old rule: "thou shalt release what you alloc/retain". So in case you use an instance field as outlet, you didn't alloc/retain it, so you shouldn't release it.

提交回复
热议问题