将黑色边框添加到集合视图的选定单元格中,并从集合视图的其他未选定单元格中删除边框

时间:2018-06-11 07:31:12

标签: objective-c uicollectionview border

我在集合视图中有7个单元格。我希望当用户选择cell1时,单元格边框变为黑色,0到6之外的其他单元格(不包括1)将显示清晰的边框颜色。

因为,我正在做以下事情: -

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
        imagePickerCell.layer.borderColor = [[UIColor blackColor]CGColor];
        imagePickerCell.layer.borderWidth = 2.0f;
}

-(void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewCell *cell =  [collectionView cellForItemAtIndexPath:indexPath];
     NSLog(@"deselected cell on imagepickerVC %ld",(long)indexPath.row);
        cell.layer.borderWidth = 0.0f;
        cell.layer.borderColor = [[UIColor clearColor]CGColor];

}

但是,它没有正常工作,好像我点击第一个单元格然后第一个将是黑色其他将是清楚但当我点击第六个单元格然后回到第一个,它显示第1和第6黑色边框。 请帮助我解决此问题,并在从其他未选定的单元格中删除边框时仅向选定的单元格添加边框。

任何形式的帮助和建议都将不胜感激。谢谢!

0 个答案:

没有答案
相关问题