Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.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/1/cocoa/3.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 选择集合视图单元格时,如何更改其背景颜色?_Ios_Objective C_Uicollectionview_Uicollectionviewcell_Uicolor - Fatal编程技术网

Ios 选择集合视图单元格时,如何更改其背景颜色?

Ios 选择集合视图单元格时,如何更改其背景颜色?,ios,objective-c,uicollectionview,uicollectionviewcell,uicolor,Ios,Objective C,Uicollectionview,Uicollectionviewcell,Uicolor,此代码是我使用的,如果选择了单元格,则背景颜色必须在图像视图中更改,它被放置在集合视图单元格中。 但它不起作用 -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { if (cell.selected) { cell.img_cell.backgroundColor = [UIColor colorFr

此代码是我使用的,如果选择了单元格,则背景颜色必须在图像视图中更改,它被放置在集合视图单元格中。 但它不起作用

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  {
      if (cell.selected) {
        cell.img_cell.backgroundColor = [UIColor colorFromHexString:@"#ffc400"]; // highlight selection
      }
      else
      {
        cell.backgroundColor = [UIColor clearColor]; // Default color
      }
      NSLog(@"Selected section>> %@",[arr_images objectAtIndex:indexPath.row]);

      //    cell.backgroundColor=[UIColor colorFromHexString:@"#ffc400"];
  }

现在它工作了,我删除了if条件并尝试使用cellForItemAtIndexPath

cell = [collectionView cellForItemAtIndexPath:indexPath];

        cell.img_cell.backgroundColor = [UIColor colorFromHexString:@"#ffc400"]; // high