gpt4 book ai didi

IOS:imageView 发生奇怪的崩溃

转载 作者:行者123 更新时间:2023-11-29 04:30:58 25 4
gpt4 key购买 nike

在我的应用程序中,我有一个带有自定义单元格的 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 委托(delegate)方法中我有这个

- (void)tableView:(UITableView *)tableView commitEditingStyle...

但是当我删除 tableView 的最后一行时,我在这里有一个 EXC_BAD 访问权限:

- (void) dealloc{
[super dealloc];
[prod release];
[back release]; <-- for this I have a EXC BAD ACCESS
}

为什么?

最佳答案

您应该在 dealloc 方法末尾调用 [super dealloc]

此外,既然你有属性(property),就好好利用它们。不直接释放,而是将 nil 分配给它们:

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

关于IOS:imageView 发生奇怪的崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11736609/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com