首页 > 解决方案 > 我正在使用集合视图,我想在最初加载视图时选择最后一个单元格,稍后用户可以取消选择它

问题描述

我正在使用集合视图,我想在最初加载视图时选择最后一个单元格,稍后用户可以取消选择它我的代码选择了最后一个单元格项目,但后来我无法取消选择它

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: NibConstants.sizeCollectionViewCellIdentifier, for: indexPath) as! SizesFilterationCollectionViewCell
        if(indexPath.row == self.mViewModel.collectionViewDumyArray.count - 1){

            cell.isSelected = true
            cell.sizeLabel.text = self.mViewModel.collectionViewDumyArray[indexPath.row]
        }else{cell.sizeLabel.text = self.mViewModel.collectionViewDumyArray[indexPath.row]}
        
        
       
        return cell
    }

这就是我选择带有文本“全部”的单元格项目的视图,但我希望稍后它也可以取消选择

标签: iosswiftxcodeswift3uicollectionview

解决方案


推荐阅读