ios - 如何将刷新控件添加到 View Controller 中的水平 collectionview?

标签 ios swift uicollectionview

我目前有:

        refresher = UIRefreshControl()
    refresher.attributedTitle = NSAttributedString(string: "Pull to refresh")
    refresher.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
    self.postsView.addSubview(refresher)

在包含 Collection View 的 View Controller 的 viewdidload() 中。与 collectionview 交互并让自定义单元格正常显示。但是,当我添加这个刷新器时,它没有做任何事情。我不确定为什么,我在这里错过了一步吗?谢谢!

最佳答案

实现 UIScrollview 委托(delegate),请尝试下面的代码

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
     CGPoint offset = scrollView.contentOffset;
     CGRect bounds = scrollView.bounds;
     CGSize size = scrollView.contentSize;
     UIEdgeInsets inset = scrollView.contentInset;
     float y = offset.x + bounds.size.width - inset.right;
     float h = size.width;


     float reload_distance = 75; //distance for which you want to load more
     if(y > h + reload_distance) {
        // write your code getting the more data
        NSLog(@"load more rows");

     }
 }

关于ios - 如何将刷新控件添加到 View Controller 中的水平 collectionview?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29189491/

相关文章:

ios - 正在主线程上执行长时间运行的 Parse 操作

ios - 如何在 Swift 中使用邮件黑猩猩发送即时电子邮件?

ios - Swift 中的 UIActivityViewController 在 iPad 上崩溃

ios - Collection View 树表示

ios - Imageview 没有出现在以编程方式创建的 Collection View 中

iphone - 使用 UINavigationController 还是 ContentController?

ios - 避免在 CoreBluetooth 中重新连接时发现服务和特征

ios - 从函数内部访问常量或变量到 `viewdidload`以保存在firebase swift 3中

ios - UICollectionView:获取不可见的 Cell 的 indexPath

ios - 如何控制阴影扩散和模糊?