Ячейка коллекции удаляет элемент при каждом вызове reloadData () Swift 5 - PullRequest
1 голос
/ 27 марта 2020

Пожалуйста, смотрите изображение ниже, это мой правильный и первоначальный вид. enter image description here

Но после вызова reloadData () для collectionView он удаляет метку состояния «ЗАВЕРШЕНО», и если я снова повторю это действие, он удалит статус «ОБРАБОТКА» метка. Кто-нибудь знает, почему он ведет себя так?

enter image description here

Это мой код cellForItemAt. * ​​1013 *

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: DFCollectionViewCellIdentifierConstants.DF_CAPTURED_PANORAMAS_CELL, for: indexPath) as! DFCapturedPanoramasCollectionViewCell
        cell.capturedPanoramasImages.layer.masksToBounds = true
        cell.capturedPanoramasImages.layer.borderWidth = 1
        cell.capturedPanoramasImages.layer.borderColor = UIColor().hexColor(DFColorConstants.INPUT_TEXT_COLOR).cgColor
        cell.capturedPanoramasImages.layer.cornerRadius = 4

        let url = URL(string:panoramaList[indexPath.item].panoramaThumbnailPath)
        if url != nil && self.panoramaList[indexPath.item].panoramaStatus == DFPanoramaStatusConstants.DF_COMPLETED {
            self.panoramaStatusLabelFunc(cell: cell, index: indexPath.item, bgColor: UIColor().hexColor(DFColorConstants.PANORAMA_STATUS_COMPLETED_COLOR))
            cell.capturedPanoramasImages.contentMode = .scaleAspectFill
            if let data = try? Data(contentsOf: url!)
            {
                let image = UIImage(data: data)
                cell.capturedPanoramasImages.image = image
            }
            cell.capturedPanoramasLabel.text = panoramaList[indexPath.item].name
        } else if url == nil && self.panoramaList[indexPath.item].panoramaStatus != DFStatusConstants.COMPLETED {
            self.panoramaStatusLabelFunc(cell: cell, index: indexPath.item, bgColor: UIColor().hexColor(DFColorConstants.PANORAMA_STATUS_UPLOADING_AND_PROCESSESING))
            cell.capturedPanoramasImages.contentMode = .scaleAspectFit
            cell.capturedPanoramasImages.image = self.capturedPanoramasImage[0]
            cell.capturedPanoramasLabel.text = panoramaList[indexPath.item].name
        } else if self.panoramaList[indexPath.item].name == DFStatusConstants.ADD_PANORAMA {
            cell.panoramaStatusLabel.isHidden = true
            cell.capturedPanoramasImages.contentMode = .center
            cell.capturedPanoramasImages.image = self.capturedPanoramasImage[1]
            cell.capturedPanoramasLabel.text = panoramaList[indexPath.item].name
        }
        return cell
    }

И PanoramaStatusLabelFun c () функция.

func panoramaStatusLabelFunc(cell: DFCapturedPanoramasCollectionViewCell, index: Int, bgColor: UIColor){
        cell.capturedPanoramasLabel.isHidden = false
        cell.panoramaStatusLabel.layer.backgroundColor = bgColor.cgColor
        cell.panoramaStatusLabel.textColor = UIColor().hexColor(DFColorConstants.TEXT_WHITE_COLOR)
        cell.panoramaStatusLabel.layer.cornerRadius = 10
        cell.panoramaStatusLabel.text = self.panoramaList[index].panoramaStatus
    }

1 Ответ

1 голос
/ 27 марта 2020

Найдена проблема, она находится в состоянии ниже с "cell.panoramaStatusLabel.isHidden = true". По какой-то причине он передает isHidden = true в следующую ячейку (я не уверен, но может быть из-за Асина)

else if self.panoramaList[indexPath.item].name == DFStatusConstants.ADD_PANORAMA 
{
    cell.panoramaStatusLabel.isHidden = true
    cell.capturedPanoramasImages.contentMode = .center
    cell.capturedPanoramasImages.image = self.capturedPanoramasImage[1]
    cell.capturedPanoramasLabel.text = panoramaList[indexPath.item].name
}

Чтобы исправить, я изменил функцию PanoramaStatusLabelFun c, как показано ниже:

    func panoramaStatusLabelFunc(cell: DFCapturedPanoramasCollectionViewCell, index: Int, bgColor: UIColor, isAddHotspot: Bool){
        cell.capturedPanoramasLabel.isHidden = false
        cell.panoramaStatusLabel.layer.backgroundColor = bgColor.cgColor
        cell.panoramaStatusLabel.textColor = UIColor().hexColor(DFColorConstants.TEXT_WHITE_COLOR)
        cell.panoramaStatusLabel.layer.cornerRadius = 10
        if(isAddHotspot) {
            cell.panoramaStatusLabel.text = ""
        } else {
            cell.panoramaStatusLabel.text = self.panoramaList[index].panoramaStatus
        }
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...