2010-03-29 89 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或其他方式来保持幻数不在那里)

相关问题