我在同一个视图控制器中有一个collectionView 和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)