本文介绍了如何释放定义为属性的IBOutlet?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,这个问题,但我进行了搜索,但没有找到该案的答案.

sorry for this question, but I searched it and I didn't find an answer for that case.

我正在研究iOS的内存管理,并且我理解(或认为是这样)视图生命周期.但是现在我对IBOutlet有一个疑问(tat链接到我的xib文件中的UIImageView).我有一个这样的班级:

I'm studying memory management for iOS and I understood, or I think so, the view lifecycle. But now I have a question on a IBOutlet (tat is linked to a UIImageView in my xib file). I have a class like this:

@interface MyClass : UIViewController 

@property (nonatomic, retain) IBOutlet UIImageView *myImage;

问题是:如何发布myImage?这样可以吗?

The question is: how can I release myImage? Is this ok?

- (void)dealloc {
    self.myImage = nil;
    [super dealloc];
}

- (void)viewDidUnload {
    [super viewDidUnload];
    self.myImage = nil;
}

有人可以解释为什么我不能在myView上调用release方法吗(如果您有喜欢的话,那也很好!)?

Can someone explain why can't I call the release method on myView (if you had some lik it is good too!)?

提前谢谢!

推荐答案

通常,您不会在属性上调用release,而是会在相应的ivar上调用它.这是我处理IBOutlet属性的标准方法:

In general, you don't call release on a property, you would call it on the corresponding ivar. This is my standard way to handle IBOutlet properties:

@interface MyClass

@property (nonatomic, retain) IBOutlet UIImageView *myImageView;
@property (nonatomic, retain) IBOutlet UILabel *myLabel;

@end


@implementation MyClass

@synthesize myImageView = _myImageView;
@synthesize myLabel = _myLabel;


- (void)dealloc {

    [_myImageView release];
    [_myLabel release];

    [super dealloc];
}

@end

这篇关于如何释放定义为属性的IBOutlet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 16:52