ios - 拉动刷新默认刷新级别更改

标签 ios objective-c uitableview uirefreshcontrol

我正在使用 UIRefreshControl。我想更改其在下拉 tableview 时的刷新操作。当 tableview 稍微下拉时我需要刷新,因为我的 tableview 高度很小,我不能下拉到足以调用刷新方法。

我该如何更改它?

我只是添加了 UIRefreshControl 如下:

self.refreshControl = [[UIRefreshControl alloc]init];
_refreshControl.tintColor = [UIColor redColor];
[self.tweetTable addSubview:self.refreshControl];
[self.refreshControl addTarget:self action:@selector(refreshTable) forControlEvents:UIControlEventValueChanged];

最佳答案

因为我不认为你可以改变你必须移动多少距离才能启动刷新的行为,所以我只会在用户滚动足够多时手动触发它,比如:

func scrollViewDidScroll(_ scrollView: UIScrollView) {
    guard !refreshControl.isRefreshing else {
        return//do nothing if we are already refreshing
    }

    //set your threshold to whatever feels ok (I used -30 here)
    if scrollView.contentOffset.y < -30 {
        refreshTable()
        refreshControl.beginRefreshing()
    }
}

当刷新处于事件状态时,您可能还需要适本地偏移表格 View ,以便 UIActivityIndi​​cator 位于您的单元格上方,然后在完成刷新后再次调整它。请注意,一旦 API 调用完成或无论您在那里做什么,您都必须在 refreshTable() 方法中调用 refreshControl.endRefreshing()。 .

关于ios - 拉动刷新默认刷新级别更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51513601/

相关文章:

ios - 如何让 iOS 应用记住用户从 UIImagePickerController 选择的图像

ios - 在 iOS 库类中的现有属性上添加属性观察器

objective-c - 如何获取字符串并从中删除部分以转换为 double

iphone - 如何避免在 UITableViewCell 上滑动删除调用 setEditing

ios - 没有找到合适的申请记录,无法获取等待上传状态

iphone - 如何为 AVAudioPlayer 制作安全的 mp3 文件,而不会出错

iOS:在更改 View 之前设置属性

ios - tableview reloadData 在展开可选值时意外崩溃发现 nil

ios - numberOfSectionsInTableView 不工作

ios - 如何在 SpriteKit 中将 Sprite 旋转 90 度