发布 iVar IBOutlet 与 Property IBOutlet

发布于 2024-11-08 13:17:19 字数 819 浏览 0 评论 0原文

谁能验证我的 dealloc 方法是否正确?由于我的 titleLabel 和 checkImageView 被保留,我将在 dealloc 中释放它们。但是,我不会释放 mainImageView、doneButton 和 noteLabel,因为它们在实现过程中不会被保留或分配。

@interface CheckMarkController : UIViewController  <UIAlertViewDelegate> {
IBOutlet UIImageView *mainImageView;
IBOutlet UIButton *doneButton;
IBOutlet UILabel *noteLabel;
}

@property (nonatomic, retain) IBOutlet UILabel *titleLabel;
@property (nonatomic, retain) IBOutlet UIImageView *checkImageView;
@property (nonatomic, retain) Event *event;
@property (nonatomic, retain) Workout *workout;
@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;

@end

- (void)dealloc {
//props
[titleLabel release];
[checkImageView release];
[event release];
[workout release];
[managedObjectContext release];

[super dealloc];

Can anyone verify my dealloc method is correct? Since my titleLabel and checkImageView are retained I am releasing them in dealloc. However, I am not releasing mainImageView, doneButton, and noteLabel, because they are not retained or alloced during the implementation.

@interface CheckMarkController : UIViewController  <UIAlertViewDelegate> {
IBOutlet UIImageView *mainImageView;
IBOutlet UIButton *doneButton;
IBOutlet UILabel *noteLabel;
}

@property (nonatomic, retain) IBOutlet UILabel *titleLabel;
@property (nonatomic, retain) IBOutlet UIImageView *checkImageView;
@property (nonatomic, retain) Event *event;
@property (nonatomic, retain) Workout *workout;
@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;

@end

- (void)dealloc {
//props
[titleLabel release];
[checkImageView release];
[event release];
[workout release];
[managedObjectContext release];

[super dealloc];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怕倦 2024-11-15 13:17:19

如果您通过 Interface Builder 连接这三个项目,则需要释放它们。默认保留插座。 KVC(Key Value Coding)用于设置插座。这意味着 loadFromNib 将为您设置的每个插座调用 setValue:withKey。这使用 @property 及其 setter 方法,但如果没有设置(如您的情况),它默认保留该对象。

If you connect these three items via Interface Builder you DO need to release them. Outlets are retained by default. KVC (Key Value Coding) is used to set outlets. This means that loadFromNib will call setValue:withKey for each outlet you have set. This uses the @property and it's setter method, but if none are set (as is your case) it retains the object by default.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文