2014-08-31 119 views
0

我的自定義單元格包含切換徽章和該徽章內的標籤(均在xib中)。那我該如何重用這個單元格呢?如果我使cell.imgBadgeImageView.image = nilcell.lblBadgeLabel.Text = nilprepareForReuse定製單元格的方法,它們都將從所有剩餘單元格中消失(因爲我們正在重新使用這些單元格)。重複使用tableview自定義單元格中的問題

我是否需要將其中的徽章和標籤添加爲代碼中的單元格的子視圖?如果我這樣做,我怎樣才能訪問單元格徽章圖像視圖和徽章標籤。我需要訪問這兩個,因爲有一個很好的動畫(用於圖像視圖)和文本更改(用於標籤)。

我目前做的所有這些都是在不使用此委託方法視圖中的細胞nil

-(void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { 
    if ([tableView.indexPathsForVisibleRows indexOfObject:indexPath] == NSNotFound){ 
     VBMerchantDealCell *cell = (VBMerchantDealCell *)[tableView cellForRowAtIndexPath:indexPath]; 
     cell = nil; 
    } 
} 

回答

1

我知道你是想重用的單元格。我不知道你採取的方法是否正確,但是我按照蘋果公司告訴我的方式來做。

a。在xib中設置重用標識符。說「MyCustomCell」。

b。在您的表格視圖分配後註冊單元格使用:

self.cellNib = [UINib nibWithNibName:@"MyCustomCell" bundle:nil]; 
[self.tableView registerNib:self.cellNib forCellReuseIdentifier:@"CustomCell"]; 

c。使用以下代碼獲取單元格到您的「cellForRowAtIndexPath」:

NSString *identifier = @"MyCustomCell"; 
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:identifier]; 
相關問題