【发布时间】:2018-06-02 19:14:17
【问题描述】:
在这里我有一个布局,其中我的一个表格视图单元格由集合视图组成,在这个我需要实现分页,我现在无法使用func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath)这个函数如何实现表格视图的分页任何人都可以帮助我如何实现它以在到达集合视图的最后一个元素时放置条件,在这里我知道如何实现分页但如何调用需要重新加载的函数?
这是我的函数,用于检测最后一个单元格并使用以下函数重新加载数据
func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
let obj = items
let lastElement = (obj.count) - 1
print(lastElement)
if !loadingData && indexPath.row == lastElement {
loadingData = true
guard let obj = self.listClassModel else { return }
if ((obj.searchCriteria.pageSize as? Int) != nil) {
self.collectionView.bottomRefreshControl?.beginRefreshing()
let viewController = HomeViewController()
viewController.loadMoreData()
}
}
func loadMoreData() {
DispatchQueue.global(qos: .background).async {
guard let obj = self.listClassModel else { return }
let totalItems = obj.totalCount
let numberOfItems = obj.searchCriteria.pageSize as! Int
let float = Float(totalItems)/Float(numberOfItems)
print(float)
let totalPages = Int(ceil(float))
print(self.count)
if totalPages != self.count {
self.index += 1
self.count += 1
print(self.count)
let batchSize = 10
let sortField = "name"
let sortOrder = "ASC"
let conditionType = "eq"
let categoryId = 1
self.listCategoryDownloadJsonWithURL(listUrl: listUrlWithParameters)
}
else {
self.loadingData = false
}
DispatchQueue.main.async {
// this runs on the main queue
self.loadingData = false
}
}
}
【问题讨论】:
-
你找到解决办法了吗?
标签: ios uitableview swift3 uicollectionview