一些细胞设置一个UITableViewCell附件类型,但不是所有的
-
23-09-2019 - |
题
我正在建立在我的UITableViewController 8个细胞。我想知道我怎么能显示在第4,8单元的披露指标。现在我建立它在
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
虽然我深知这是要披露指示器添加到每个细胞
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
解决方案
使用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
}
其他提示
您知道indexPath,所以为什么不只是有条件地适用披露指标时
if((indexPath.row == 3) || (indexPath.row == 7))
(indexPath.row是以0当然...第四是3和8号是7,您应使用#define语句或其他方式来保持幻数出来的有太多。)
不隶属于 StackOverflow