2010-03-22 104 views
2

我有2個按鈕的自定義單元格(這些按鈕的功能只是爲了禁用按下按鈕)。 當我使用dequeueReusableCellWithIdentifier在這個經典方式:問題與dequeueReusableCellWithIdentifier,自定義UITableViewCell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
static NSString *CellIdentifier = @"Cell"; 
cell = ((MainCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]); 
if (cell == nil) { 
[[NSBundle mainBundle] loadNibNamed:@"MainCell" owner:self options:nil]; 
} 
    return cell; 
} 

所述的UITableView有1個節,問題是:在當我按下按鈕禁用它比向下滾動來顯示其它細胞,當我第一小區再次向上滾動第一個單元格是一個新的單元格,並且該按鈕已啓用。 我知道如果已經創建了reuseIdentifier,就不會重新創建一個單元格,但這樣我就失去了所有不可見的單元格的所有信息。

有什麼想法?

在此先感謝

回答

4

我有類似的問題 - 我認爲這個問題是隻可見單元格實際上是在內存中的任何給定的時間,當它重新顯示舊小區,它實際上只是一個出列新的一個。我認爲解決的辦法是使用- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath委託方法:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { 
    id objectForCell = [self.arrayOfThingsForTableView objectAtIndex:indexPath.row]; 
    if (!objectForCell.button1IsEnabled) { 
     cell.button1.enabled = NO; //or something along those lines 
    } else { 
     cell.button1.enabled = YES; //necessary so that all the other buttons don't disable 
    } 
} 

如果任何人有一個更好的解決方案,我會非常高興聽到這個消息。

-1

使用此:

IGECellBasic *cell = [[[IGECellBasic alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
+1

凡在那裏爲'IGECellBasic'文檔? – Sam 2011-10-06 23:05:48

+0

這就是我的UITableViewCell的子類 – Ondrej 2011-10-07 20:59:58