[英]IOS: strange crash for an imageView
In my app I have a tableView with custom cell, this is .h of custom cell 在我的应用中,我有一个带有自定义单元格的tableView,这是自定义单元格的.h
@interface TableViewCell : UITableViewCell{
IBOutlet UILabel *prod;
IBOutlet UIImageView *back;
}
@property (nonatomic, retain) IBOutlet UILabel *prod;
@property (nonatomic, retain) IBOutlet UIImageView *back;
and it's .m 它是.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
in my delegate methods of tableView I have this 在我的tableView委托方法中,我有这个
- (void)tableView:(UITableView *)tableView commitEditingStyle...
but when I delete last row of my tableView I have an EXC_BAD ACCESS here: 但是,当我删除tableView的最后一行时,这里有一个EXC_BAD ACCESS:
- (void) dealloc{
[super dealloc];
[prod release];
[back release]; <-- for this I have a EXC BAD ACCESS
}
why? 为什么?
You should call [super dealloc]
at the end of your dealloc
method. 您应该在
dealloc
方法的末尾调用[super dealloc]
。
Additionally, as you've properties, make use of them. 此外,当您拥有属性时,请充分利用它们。 Instead of releasing directly assign
nil
to them: 与其直接释放,不给它们分配
nil
:
- (void)dealloc
{
self.prod = nil;
self.back = nil;
[super dealloc];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.