Question

How could I easily dim the complementary set of rows, when one gets selected.

Right now I have the code to select a cell so I can call a method on it, but I would like to set opacity of all the other rows.

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

Edit: I dont want to iterate through all the other cells (because there will be a lot of them) - wouldn't it be easier to add an UIView above all other cell (this would also prevent user interaction) and place the selected cell above that view (something like increasing z-index in HTML).

No correct solution

OTHER TIPS

It depends what you mean by "dim" the other rows. The process to iterate over all visible rows and to set a property on all the rows other than the one selected is as follows:-

- (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
        }
    }
}

Where my comment is, you can set whatever properties you like on otherCell. For example, otherCell.alpha which is the alpha (transparency) of that cell.

You can iterate all the visible cells, configure them to be dimmed, then on the datasource cellForIndex method check if there's a selected cell, if there is, check if it is at the asked index, if so configure the cell as selected, if not as dimmed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top