[英]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.