我有一个自定义的UITableViewCell,暂且叫ACell,该cell有以下属性:
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIButton *deleteButton;
全部addSubview到cell的contentView,主要是点击deleteButton之后把titleLabel移除:
- (void)deleteButtonClicked {
[self.titleLabel removeFromSuperview];
}
执行以上语句之后我发现,titleLabel还是存在于内存中。就像下面这样:
怎么样才能让它立即销毁
原因是:ACell 依然持有 titleLabel 物件。
解決方法:
self.titleLabel = nil;
把strong換成weak,注意一點就是,在addsubview 之後再給屬性複製