Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UICollectionViewCell是否更改行单元格(行)的背景?_Ios_Objective C_Uicollectionviewcell - Fatal编程技术网

Ios UICollectionViewCell是否更改行单元格(行)的背景?

Ios UICollectionViewCell是否更改行单元格(行)的背景?,ios,objective-c,uicollectionviewcell,Ios,Objective C,Uicollectionviewcell,如何选择单元格-更改行单元格(行)的背景? 我不知道如何获取行单元格的indexpath。一个选择单元可以毫无问题地更改颜色。 我需要更改整行的背景。请。帮帮我 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,

如何选择单元格-更改行单元格(行)的背景? 我不知道如何获取行单元格的indexpath。一个选择单元可以毫无问题地更改颜色。 我需要更改整行的背景。请。帮帮我

    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]];



只写这个

    if (cell.selected) 
     {
          cell.backgroundColor = [UIColor redColor]; // highlight selection 
     }
   else
     {
          cell.backgroundColor = [UIColor grayColor]; // Default color
     }

为什么不将
中的每个记录都设置为一个节,并检查
[selectedIndexPath节]
然后在
单元格中为ItemAtIndexPath:
如果
[indexPath节]
等于
[selectedIndexPath节]
可以为该节中的所有行上色


祝你好运

你的didSelectItemAtIndexPath是CollectionView,因此你可以更改整行的颜色…你只更改所选项目的背景颜色。是的,我使用didSelectItemAtIndexPath,但我只能更改一个单元格的背景颜色。我是如何获得整行的indexpatch的?因为颜色只会改变单击的单元格。当你点击一行(行)中的一个单元格时,我需要它——改变了这行(行)的颜色。如何更改邻近单元格的颜色?在最后一种情况下,应在选定单元格的交点处垂直和水平更改背景线。
    - (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];
}
    if (cell.selected) 
     {
          cell.backgroundColor = [UIColor redColor]; // highlight selection 
     }
   else
     {
          cell.backgroundColor = [UIColor grayColor]; // Default color
     }