如何在iOS的CollectionView的页脚中添加加载指标
当数据加载到下一页时,如何在集合视图的页脚中添加加载指示器..?
我想要加载指标在收集视图的页脚与上面的图像相同。 但我无法做到这一点。
那么有没有可能? 否则,我必须使用tableview创build这种types的列表视图。 因为我们可以轻松地将这些东西pipe理成tableview。
任何帮助,将不胜感激。
在CCBottomRefreshControl的帮助下,我发现了一个非常简单的解决scheme,您只需要像简单的UIRefreshController
let bottomRefreshController = UIRefreshControl() bottomRefreshController.triggerVerticalOffset = 50 bottomRefreshController.addTarget(self, action: #selector(ViewController.refreshBottom), forControlEvents: .ValueChanged) collectionView.bottomRefreshControl = bottomRefreshController func refreshBottom() { //api call for loading more data loadMoreData() }
而你认为你应该停止装载机
collectionView.bottomRefreshControl.endRefreshing()
在viewcontroller的底部添加一个uiview的最简单的方法是添加一个activityindicator到该视图并设置视图的属性隐藏来检查,创build一个IBOutlet的视图,而加载数据从服务器设置sockets的属性hidden = NO数据加载后再次隐藏视图。 我在使用uicollectionviews或uitableview的应用程序中做了同样的事情
编辑
另一种方法是在collectionview或tableview的页脚中添加加载指示符,然后在下面的方法中进行networking调用
对于Collectionview:
- (void)collectionView:(UICollectionView *)collectionView willDisplaySupplementaryView:(UICollectionReusableView *)view forElementKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath;
对于TableView:
- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section;
窗体接口生成器,
在“ Attribute inspector
,选中“ Collection View
请检查“ Accessories
的Section Footer
。 所以,它会在你的集合视图中添加footerview,你可以很容易地将活动指标拖放到这个footerView
。
希望这可以帮到你。 🙂
开源的libiary MJRefresh是一个不错的select,你可以轻松地添加一个刷新脚。 如果你想使用你的图像相同的animation,也许你应该使用GIF图像使用MJRefreshAutoGifFooter类。 该项目包括相同的例子,您可以下载并尝试在您的设备上。