【发布时间】:2021-10-15 13:02:39
【问题描述】:
我正在使用带有分页的 collectionView,但 willDisplay 方法被多次调用,我不知道为什么。如果有人有任何想法,请帮助我...................................................... ......
func collectionView(_ collectionView: UICollectionView, willDisplay cell: func scrollViewDidScroll(_ scrollView: UIScrollView) {
guard gridCollectionView!.contentOffset.y >= (gridCollectionView!.contentSize.height - gridCollectionView!.bounds.size.height),
!isRefreshing else { return }
isRefreshing = !isRefreshing
offset += limit
getAllExcrcise(keyword: "", limit: limit, offset: offset)
}
API调用函数
func getAllExcrcise(keyword: String = "", limit: Int = 10, offset: Int = 0, clearAll:Bool = false) {
if clearAll {
self.allExcercise.removeAll()
}
var params = [String: Any]()
params = [
"keyword": keyword,
"limit": limit,
"offset": offset,
"muscle" : bodyPartSelectedArr,
"equipment": categorySelectedArr
]
WebServiceHelper.postWebServiceCall(Constants.baseURL + "getAllExcercises", params: params, isShowLoader: true, success: { (responceObj) in
let statusMsg = GetAllExcerciseLevelOneData(json: responceObj)
if statusMsg.status {
let respArr = responceObj["data"].arrayValue
for item in respArr {
let dataModel = GetAllExcercise(json: item)
for selectedVal in self.selectedItem {
if selectedVal.id == dataModel.id {
dataModel.isCellSelected = true
}
}
self.allExcercise.append(dataModel)
}
self.totalPages = statusMsg.totalPages
} else {
//CommonUtils.showToastMessage(message: statusMsg.message ?? "")
}
self.tableView?.reloadData()
self.gridCollectionView?.reloadData()
}
, failure: { (failure) in
print(failure)
})
}
【问题讨论】:
-
在表格/集合视图中每个单元格加载之前将显示方法调用
-
那么我将如何实现分页
-
你可以使用 UIScrollViewDelegate。
-
你能用代码解释一下吗
-
你想实现哪个滚动方向的分页?
标签: ios swift uicollectionview uikit