iphone - 自定义UITableViewCell在[super dealloc]上崩溃

标签 iphone objective-c ios memory-management uitableview

我有一个UITableViewCell的子类,当它到达[super dealloc]行时会崩溃。我的单元格中有几个textField,错误消息是*** -[UITextField release]: message sent to deallocated instance 0x739dfd0
下面是相关的代码片段(我确实有其他textField,但是它们都以相同的方式处理。我怀疑是将其添加到单元格的contentView中。但是我不知道如何纠正它。

自定义UITableViewCell的.h文件:

@interface ExerciseTableViewCell : UITableViewCell {

    UITextField *textField1;

}

@property (nonatomic, retain) UITextField *textField1;

@end

.m文件:
@implementation ExerciseTableViewCell

@synthesize textField1;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code

    UIView *myContentView = self.contentView;

        UITextField *newTextField1 = [[UITextField alloc] init];

        self.textField1 = newTextField1;

        [newTextField1 release];

        [myContentView addSubview:textField1];

    }
    return self;
}


}

- (void)dealloc {
    [textField1 release];
    [super dealloc];
}

我看不到为什么我会多次释放textField?

最佳答案

更改:

UITextField *newTextField1 = [[UITextField alloc] init];

self.textField1 = newTextField1;

[newTextField1 release];

[myContentView addSubview:textField1];

至:
self.textField1 = [[[UITextField alloc] init] autorelease];
[myContextView addSubview:self.textField1];

关于iphone - 自定义UITableViewCell在[super dealloc]上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10674165/

相关文章:

ios - 删除大标题 UINavigationBar 中 UISearchController 顶部的 1px 行

ios - navigator.mediaDevices.getUserMedia() 不适用于 iOS 11 独立应用程序

iphone - 在框架中打开 iPhone 相机

iOS 一分钟内杀死在后台运行的 CallKit VoIP 应用程序

c++ - 在哪里可以找到高效的 R-Tree 实现?

iphone - 无法使用自动布局显示控件添加到 ScrollView 的内容 View 中

iphone - 对 <TSActivityMapVC : 0x81b1000> 的开始/结束外观转换的调用不平衡

ios - 带有禁用按钮的 UIActionSheet?

ios : How to get photo url which is deleted in photo. 应用程序

ios - 自定义单元格按钮单击