我有一个显示项目的 UICollection View 。现在我想在 UICollectionView 上添加分页。我不想使用任何第三方来实现此功能。请告诉我如何实现这一目标!
我有四个一个例子http://slicode.com/bottom-refresh-control-uicollectionview/
但在此我必须向上拖动 scrollview 几秒钟才能使其工作。
最佳答案
简单的方法做到这一点
var page: Int = 0
var isPageRefreshing:Bool = false
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
YourApi(page1: 0)
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if(self.mycollectionview.contentOffset.y >= (self.mycollectionview.contentSize.height - self.mycollectionview.bounds.size.height)) {
if !isPageRefreshing {
isPageRefreshing = true
print(page)
page = page + 1
YourApi(page1: page)
}
}
}
在你的 api 方法中
func YourApi(page1: Int) {
let mypage = String(page1)
let request: String = String.init(format:"apiName/%@", mypage)
print(request)
}
就是这样。
关于ios - 如何快速在 UICollectionView 中添加分页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51282164/