【发布时间】:2010-11-16 07:55:39
【问题描述】:
在大多数示例中,我看到以下 IBOutlets 设置:
(Example A)
FooController.h:
@interface FooController : UIViewController {
UILabel *fooLabel;
}
@property (nonatomic, retain) IBOutlet UILabel *fooLabel;
@end
FooController.m:
@implementation FooController
@synthesize fooLabel;
@end
但这也很好用(注意:没有属性也没有合成):
(Example B)
FooController.h:
@interface FooController : UIViewController {
IBOutlet UILabel *fooLabel;
}
@end
FooController.m:
@implementation FooController
@end
在示例 B 中定义 IBOutlets 有什么缺点吗?比如内存泄漏?似乎工作正常,我更喜欢不将 IBOutlets 公开为公共属性,因为它们不是这样使用的,它们仅在控制器实现中使用。在没有真正需要的情况下在三个地方定义它并不会让我觉得非常干燥(不要重复自己)。
【问题讨论】: