這裏是我的代碼:從故事板中加載自定義的UITableViewCell沒有得到dealloc'ed
__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不是。 我在儀器中看到,每次創建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;
這裏任何幫助,將不勝感激。 謝謝!
編輯: 我的tableView本身沒有得到dealloc'ed後currentViewController獲得dealloc'ed。 嘗試登錄UITableView類別。 不過,猜測,當我的viewController已經發布時,爲什麼我的tableView不會被釋放。似乎太奇怪了。
當你檢查單元是否被釋放?單元由tableView擁有,它可以重用單元,所以它不會釋放它們。 tableView由控制器的視圖(父)擁有,並且當視圖控制器被取消分配時,所有對象都將被釋放。 –
回答@LucianBoboc:即使在CurrentViewController被取消分配之後,我看到單元沒有被釋放(在Instruments [Allocations工具]中)。 另外,自定義單元格中的「dealloc」方法沒有被調用。 這些方法適用於「cellForRowAtIndexPath」方法。 – CoderSaru
你使用ARC嗎? – hasan83