2012-01-23 25 views
1

我的問題是爲this相似:的iOS UITableViewCell的選擇性細胞顯示accessoryView的

但是我想表明與DetailDisclosureButton accessoryView的僅適用於具有詳細信息的細胞。

我已經寫了一些代碼,但我不知道用哪種方法。

if (totalcount == 0 && totalcount2 == 0) 
{ 
    cell.accessoryType = UITableViewCellAccessoryNone; 
} 

else 
{ 
    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 
} 

totalcount和totalcount2是兩個可變數組的計數,告訴我細胞是否有細節。

請問我是否我的問題不清楚,謝謝。

回答

4
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString* identifierString; 

    if(totalCount == 0 && totalCount2 == 0) { 
     identifierString = @"0"; 
    } else { 
     identifierString = @"1"; 
    } 

    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:identifierString]; 

    if(cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:YOUR_CELL_STYLE 
      reuseIdentifier:identifierString] autorelease]; 

     if ([identifierString intValue] == 0) { 
      cell.accessoryType = UITableViewCellAccessoryNone; 
     } else { 
      cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 
     } 

     //do whatever setup you need to do 
    } 

    return cell; 
} 

雖然我後添加到tableView:cellForRowAtIndexPath:,看來,如果totalCount和totalCount2都等於0,那麼所有單元將具有相同的附件類型。那是你什麼?如果不是,你可能想重新考慮你的邏輯。

+0

感謝您的幫助。你是對的,我必須重新思考我的邏輯。我認爲「細胞」是個體,但我意識到它是全部或沒有。 – wagashi

+0

這段代碼解決了你的問題嗎? –

+0

最後,我有時間來測試這個,這部分解決了,但你知道如何在UITableViewCell *單元初始化之前讀取cell.textLabel.text嗎? – wagashi

2

你應該做的是在tableView:cellForRowAtIndexPath:,當你設置你的UITableViewCell

1

這種細胞已被傳離隊或初始化