[英]IOS: strange crash for an imageView
在我的应用中,我有一个带有自定义单元格的tableView,这是自定义单元格的.h
@interface TableViewCell : UITableViewCell{
IBOutlet UILabel *prod;
IBOutlet UIImageView *back;
}
@property (nonatomic, retain) IBOutlet UILabel *prod;
@property (nonatomic, retain) IBOutlet UIImageView *back;
它是.m
@implementation TableViewCell
@synthesize prod, back;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void) dealloc{
[super dealloc];
[prod release];
[back release];
}
@end
在我的tableView委托方法中,我有这个
- (void)tableView:(UITableView *)tableView commitEditingStyle...
但是,当我删除tableView的最后一行时,这里有一个EXC_BAD ACCESS:
- (void) dealloc{
[super dealloc];
[prod release];
[back release]; <-- for this I have a EXC BAD ACCESS
}
为什么?
您应该在dealloc
方法的末尾调用[super dealloc]
。
此外,当您拥有属性时,请充分利用它们。 与其直接释放,不给它们分配nil
:
- (void)dealloc
{
self.prod = nil;
self.back = nil;
[super dealloc];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.