Alk*_*Alk 2 asynchronous ios uicollectionview uirefreshcontrol swift
我有一个UICollectionView显示来自在线数据库的图像.我首先加载10个图像,然后当用户滚动到底部时,UICollectionView我在后台加载另外10个图像并刷新视图.我使用以下方法完成此操作:
func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) {
if (self.localFeedContent != nil && self.localFeedContent!.count > 0) {
if indexPath.item == (self.localFeedContent!.count-1) {
loadMoreData()
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在这完全正常,但没有迹象表明用户该过程已完成,除非他向下滚动,否则他不会注意到已添加新内容.我想实现一个UIRefreshControl将附加到底部UICollectionView并且模仿与UIRefreshControl屏幕顶部的常规相同的确切行为.我已经在屏幕顶部实现了一个,但我不知道如何在底部执行此操作.
Dav*_*ven 12
我写了类似的东西 - 我返回底部的另一个单元格,只显示一个UIActivityIndicator.所以你的数据源类似于:
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return array.count + 1
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
if indexPath.item == array.count{
// return the new UICollectionViewCell with an activity indicator
}
// return your regular UICollectionViewCell
}
func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) {
if indexPath.item == array.count{
// loadMoreData()
}
}
Run Code Online (Sandbox Code Playgroud)
或者,而不是调用loadMoreData()中willDisplayCell,你可以把它的cellForItemAtIndexPath方法(当你返回新UICollectionViewCell用UIActivityIndicator).要么可以工作.
| 归档时间: |
|
| 查看次数: |
8861 次 |
| 最近记录: |