2013-08-16 27 views
0

我使用ARC,但似乎我的自定義UITableCellView沒有發佈。UITableCell子類永不釋放?

TBMListingLineView是TBMGlobalCustomCell的子類,它是UITableCellView的子類。

在TBMListingLineView有10個UILabels(非原子,保留)

我已經在這兩個類中實現它永遠不會被調用(斷點不停止執行)

當我的方法的dealloc滾動TableView,UILabel的數量在Instruments/Allocations中增加,導致應用程序在幾次內存警告後崩潰。

enter image description here

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

static NSString *CellIdentifier = @"Cell"; 

TBMGlobalCustomCell* cell; 

cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

switch(sortIndex) { 
    case 0 : 
     cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil || ![cell isKindOfClass:[TBMListingLineView class]]) { 
      cell = [[TBMListingLineView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
     } 

    break; 

....

return cell; 

}

+0

爲什麼你調用'dequeueReusableCellWithIdentifier'兩次?如果你的自定義單元是TBMGlobalCustomCell對象,爲什麼要檢查'[TBMListingLineView類]? –

+0

爲什麼要兩次調用dequeueReusableCellWithIdentifier? - > omg ...就是這樣!謝謝 !爲了回答第二個問題,我有5個TBMGlobalCustomCell的不同子類,並且根據sortIndex值,TableCellView不同,再次感謝 – Max

+1

但是調用dequeueReusableCellWithIdentifier,然後用新分配的元素替換出隊單元也沒有意義。更好地爲每個子類使用不同的單元格標識符。 –

回答

2

第一個問題是,你叫dequeueReusableCellWithIdentifier兩次,每次細胞。 然後,如果它沒有合適的課程,那麼你「扔掉」第二個出隊的單元格。

更好的解決方案是使用不同的小區標識符對每個小區(子)在 表格視圖中使用的類,從而使正確 類的dequeueReusableCellWithIdentifier返回實例。