【发布时间】:2015-08-09 08:59:00
【问题描述】:
这是我的代码:
__weak CurrentViewController *weakSelf = self;
if (indexPath.row == 0) //Name Cell
{
static NSString *CellIdentifier = @"NameCell";
NameCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
__weak NameCell *weakCell = cell;
cell.NameDidChangeBlock = ^(){
weakSelf.zoneName = weakCell.NameTextField.text;
};
return cell;
}
else if (indexPath.row == 1) //Number Cell
{
static NSString *CellIdentifier = @"NumberCell";
NumberCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.someBlock = ^(){
[weakSelf.navigationController popViewControllerAnimated:YES];
};
return cell;
}
“NameCell”和“NumberCell”dealloc 方法都没有被调用。 我将这两个自定义单元格设计为 CurrentViewController 的故事板中的顶级对象。
CurrentViewController 的 dealloc 被调用,但自定义单元格的 dealloc 没有。 我在 Instruments 中看到,每次创建 CurrentViewController 实例时,自定义单元格的 retainCount 都会增加。
这是我的自定义单元格标题:
//NameCell.h:
@property(nonatomic, weak)IBOutlet UITextField *NameTextField;
@property (nonatomic, copy)NameDidChange NameDidChangeBlock;
//NumberCell.h
@property(nonatomic, weak)Manager *manager;
@property(nonatomic, weak)IBOutlet AKPickerView *pickerView;
@property(nonatomic, strong)NSArray *numbersArray;
@property(nonatomic)int selectedZoneNumber;
@property (weak, nonatomic) IBOutlet UIView *selectionBoxView;
@property (nonatomic, copy)some someBlock;
我们将不胜感激。 谢谢!
编辑: 在 CurrentViewController 被释放后,我的 tableView 本身没有被释放。 试图通过 UITableView 类别登录。 不过,猜测,为什么当我的 viewController 已经发布时我的 tableView 不会被释放。好像太诡异了。
【问题讨论】:
-
您何时检查单元格是否被释放?单元格归 tableView 所有,它可以重用单元格,因此不会释放它们。 tableView 归控制器的视图(父)所有,当视图控制器被释放时,所有对象都将被释放。
-
回答@LucianBoboc:即使在 CurrentViewController 被释放后,我也看到单元格没有被释放(在仪器 [分配工具] 中)。此外,自定义单元格中的“dealloc”方法不会被调用。这些方法用于“cellForRowAtIndexPath”方法。
-
单元格块看起来不错,使用了弱变量。
-
Answering @hasan83: 是的,我正在使用 ARC,我对所有强对象设置了 nil。
-
由于您使用的是 ARC,因此您不必为强对象设置 nil。对?但是,我还不知道你的问题是什么。
标签: ios objective-c uitableview storyboard