im使用alamofire来为收集视图下载数据,我在请求中使用分页来结束时获取更多数据,但由于某种原因,第一次收集加载数据,请再次调用加载数据g,直到加载87然后从sopt加载记录。所有图像也变得很奇怪,因为正在将一个图像发送到另一单元格,并且即使收藏夹尚未滚动也无法正确显示 这是我的收藏代码。
progen1 = parents.splice(n1, 1)[0];
也是loadData功能代码
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! compisCell
//let indexValue: Int = 3 * indexPath.section + indexPath.row
cell.nameLabel.text = requestManager.instance.compis[indexPath.row].firstName //3 * indexPath.section +
cell.nameLabel.adjustsFontSizeToFitWidth = true
cell.percentlabel.text = Int(requestManager.instance.compis[indexPath.row].percent!).description + " %" //3 * indexPath.section +
if let image = requestManager.instance.compis[indexPath.row].image{ //3 * indexPath.section +
cell.userImage.sd_setImage(with: URL(string: Router.baseURLString + (image.path.replacingOccurrences(of: "images", with: "/photo"))), completed: nil)
}else{
cell.userImage?.contentMode = .center
}
cell.userImage.layer.cornerRadius = cell.userImage.frame.width / 2
cell.userImage.clipsToBounds = true
cell.imageHolder.layer.borderWidth = 1.0
cell.imageHolder.layer.borderColor = lightBlue.cgColor
cell.imageHolder.layer.cornerRadius = cell.imageHolder.frame.width / 2
return cell
}
func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
if indexPath.row == (requestManager.instance.compis.count - 2) && !iswaiting {
iswaiting = true
loadData()
}
}
Any Idea如何停止奇怪的下载。
问题是,即使因为单元格尚不可见,也不能调用willDisplayCell,即使collectionView尚未滚动也要调用。