我在一个具有单独视图的同一个viewcontroller中有一个collectionView和tableview。我正在使用Kingfisher下载图像。我可以毫无问题地滚动tableview。但是当我滚动collectionview时,应用程序会冻结,并且在一段时间之后应用程序崩溃并获得调试消息为"来自调试器的消息:由于内存问题而终止"。
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
}
这是我的collectionView方法
当我删除了estimatedItemSize时,滚动效果很好,但我不能根据标签内容调整单元格大小。
self.collectionFlowOut.estimatedItemSize = CGSize(width: 1, height: 1)
答案 0 :(得分:0)
只需删除
cell.layoutIfNeeded()
cell.setNeedsLayout()
为什么以这种方式打电话给他们