2010-03-29 59 views
6

我有8個單元正在構建在我的UITableViewController中。我想知道如何在第4和第8格顯示披露指標。現在我建立它在在某些單元上設置UITableViewCell附件類型,但不是全部

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

雖然我深知這是要披露指示器添加到每個細胞

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

回答

18

使用一個簡單的if語句:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    ... // do whatever 
    UITableViewCellAccessoryType accessoryType = UITableViewCellAccessoryNone; 
    if (indexPath.row == 3 || indexPath.row == 7) { 
     accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    } 
    cell.accessoryType = accessoryType; 
    ... // do whatever 
} 
+0

@EthanB我現在看到了這種情況。 – Morkrom 2015-06-04 03:06:22

+0

@Morkrom我現在有足夠的代表來自己修復它。 :) – EthanB 2015-06-04 16:54:46

2

你知道indexPath,所以爲什麼不只是有條件地申請公開指示當

if((indexPath.row == 3) || (indexPath.row == 7)) 

(indexPath.row當然是基於0的...第4個是3和第8個是7.你應該使用#defines或其他方式來保持幻數不在那裏)

相關問題