Paul Heinemeyer Paul Heinemeyer - 5 months ago 31
Swift Question

How to get access to all cells at the Method didSelectItemAtIndexPath() in a UICollectionViewController (Swift)

how can set values of any cell in my collection view at didSelectItemAtIndexPath. So i want to change the border color of all other cells to black expect the cell the user clicked.

Thank you


The following code iterates through the tableview sections, and each sections's rows. It compares the indexPath of each row to the indexPath of the selected cell, and if they don't match, allows you to do what you need to do to the cell.

for (NSInteger i = 0; i < [tableView numberOfSections]; ++i)
    for (NSInteger j = 0; j < [tableView numberOfRowsInSection:i]; ++j)
        NSIndexPath *cellIdxPath = [NSIndexPath indexPathForRow:j inSection:i];

        // indexPath represents the currently selected row
        if (indexPath != cellIdxPath)
            UITableViewCell *cell = [tableView cellForRowAtIndexPath:cellIdxPath];
            // do whatever you need to do to the cell