Горизонтальный collectionView зависает при прокрутке - PullRequest
0 голосов
/ 08 мая 2018

У меня есть collectionView и tableview в одном и том же viewcontroller с отдельными представлениями. Я использую Kingfisher для загрузки изображений. Я могу прокручивать таблицу без проблем. Но когда я прокручиваю коллекцию, приложение зависает, и через некоторое время происходит сбой приложения, и появляется сообщение отладки «Сообщение отладчика: прекращено из-за проблемы с памятью».

This is the screen shot

func setupCollectionView(){
    let cell = UINib(nibName: "FilterCollectionCell", bundle: Bundle(for: FilterCollectionCell.self))
    self.collectionView.register(cell, forCellWithReuseIdentifier: "FilterCollectionCell")
    self.collectionFlowOut.estimatedItemSize = CGSize(width: 1, height: 1)
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return self.sharedData.offerDetails.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "FilterCollectionCell", for: indexPath) as! FilterCollectionCell

    if self.sharedData.offerDetails.count > indexPath.row{
        let offerDetail = self.sharedData.offerDetails[indexPath.row]
        cell.price.text = offerDetail.currency + " " + offerDetail.lowestFare.withCommas()

        if let firstSector = offerDetail.flightDetails.first,
            let firstOption = firstSector.options.first,
            let firstSegment = firstOption.flightSegments.first{
            cell.flightName.text = firstSegment.airlineName
            let imgURL = self.sharedData.imageURL.replacingOccurrences(of: "{airlineID}", with: firstSegment.airlineCode)
            let placeholderImage = UIImage(named: "AirlineIcon")
            let url = URL(string: imgURL)
            cell.logoImage.kf.indicatorType = .activity
            cell.logoImage.kf.setImage(with: url, placeholder: placeholderImage, options: [], progressBlock: nil, completionHandler: nil)
        }
    }
    cell.backgroundColor = UIColor.clear
    cell.layoutIfNeeded()
    cell.setNeedsLayout()
    return cell
}

Это моя коллекция. Методы просмотра

Когда я удалял оцененный размер элемента, прокрутка работает отлично, но я не могу подогнать размер ячейки в зависимости от содержимого метки.

        self.collectionFlowOut.estimatedItemSize = CGSize(width: 1, height: 1)

1 Ответ

0 голосов
/ 08 мая 2018

Просто удалите

cell.layoutIfNeeded()
cell.setNeedsLayout()

почему вы их так называете

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...