如何選擇一個單元格 - 更改行單元格(行)的背景? 我不知道如何獲得行線單元格的索引路徑。一個選擇單元格改變顏色沒有任何問題。 我需要改變整個行的背景。請。幫我UICollectionViewCell更改行單元格(行)的背景?
Array *cellArray = @[ @[@0, @0, @0, @2, @6, @0, @7, @0, @1],
@[@6, @8, @0, @0, @7, @0, @0, @9, @0],
@[@1, @9, @0, @0, @0, @4, @5, @0, @0],
@[@8, @2, @0, @1, @0, @0, @0, @4, @0],
@[@0, @0, @4, @6, @0, @2, @9, @0, @0],
@[@0, @5, @0, @0, @0, @3, @0, @2, @8],
@[@0, @0, @9, @3, @0, @0, @0, @7, @4],
@[@0, @4, @0, @0, @5, @0, @0, @3, @6],
@[@7, @0, @3, @0, @1, @8, @0, @0, @0]];
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
//code
if ([self.selectedIndexPath isEqual:indexPath]) {
cell.backgroundColor = [UIColor redColor];
// set highlight color
} else {
cell.backgroundColor = [UIColor grayColor];
// set default color
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSArray *arrayOfIndexPaths = [self.collectionView indexPathsForSelectedItems];
if (indexPath && [self.board isEditableFieldAtIndex:indexPath.row]) {
NSMutableArray *indexPathsToReload = [@[indexPath] mutableCopy];
if (self.indexPathForLastCellMarkedEditing && ![self.indexPathForLastCellMarkedEditing isEqual:indexPath]) {
// if one cell was already marked, we have to unmark it
[indexPathsToReload addObject:self.indexPathForLastCellMarkedEditing];
}
self.indexPathForLastCellMarkedEditing = indexPath;
[self.collectionView reloadItemsAtIndexPaths:indexPathsToReload];
}
else {
[self unmarkCells];
}
self.indexPathForLastCellMarkedEditing = indexPath;
[self.collectionView reloadItemsAtIndexPaths:arrayOfIndexPaths];
[self.collectionView reloadData];
}
你didSelectItemAtIndexPath顏色的所有行? ????? –
Tis是CollectionView,因此您可以更改整行的顏色...您只更改所選項目的背景顏色。 –
是的,我使用didSelectItemAtIndexPath,但我只能更改一個單元格backgroundColor。我如何獲得整行的indexpatch? – Fabio