1

当一个被选中时,我怎么能轻松地使互补的一组行变暗。

现在我有选择一个单元格的代码,所以我可以在它上面调用一个方法,但我想设置所有其他行的不透明度。

-(void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    SummaryCell * selectedCell = [tableView cellForRowAtIndexPath:indexPath];
    [selectedCell manageContent];
}

编辑:我不想遍历所有其他单元格(因为会有很多) - 在所有其他单元格上方添加 UIView 会不会更容易(这也会阻止用户交互)并放置选定的单元格在该视图上方(类似于在 HTML 中增加 z-index)。

4

2 回答 2

2

这取决于您所说的“暗淡”其他行是什么意思。遍历所有可见行并在除所选行之外的所有行上设置属性的过程如下:-

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    for (UITableViewCell *otherCell in self.tableView.visibleCells) {
        NSIndexPath *otherIndexPath = [self.tableView indexPathForCell:otherCell];
        if (![indexPath isEqual:otherIndexPath]) { // exclude the selected cell
            // Do whatever you want with otherCell here
        }
    }
}

我的评论在哪里,你可以设置你喜欢的任何属性otherCell。例如,otherCell.alpha这是该单元格的 alpha(透明度)。

于 2012-08-20T10:13:40.393 回答
1

您可以迭代所有可见单元格,将它们配置为变暗,然后在数据源 cellForIndex 方法上检查是否有选定的单元格,如果有,检查它是否在要求的索引处,如果有,将单元格配置为选中,如果没有变暗。

于 2012-08-20T10:06:43.117 回答