我在UITableViewController中构建了8个单元格。我想知道如何在第4和第8个细胞上显示披露指标。现在我正在
中构建它- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
虽然我完全知道它会为每个单元格添加一个披露指标
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
答案 0 :(得分: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
}
答案 1 :(得分:2)
你知道indexPath,所以为什么不在
时有条件地应用披露指标if((indexPath.row == 3) || (indexPath.row == 7))
(indexPath.row当然是从0开始的......第4个是3,第8个是7个。你应该使用#defines或其他方式来保持魔术数字不在那里。)