ios - 在没有 UITableViewController 的情况下拉取刷新 UITableVi

我正在尝试在 UIViewController 内的 UITableView 中实现拉动刷新功能。我不能使用 UITableViewController 因为我希望 UITableView 是 View Controller 中的一个较小的 subview ,上面还有一些其他的东西。我认为这是可能的,但有人看过它的实现吗?

最佳答案

不使用 UITableViewController 直接向 UITableView 添加刷新控件:

override func viewDidLoad() {
    super.viewDidLoad()
    let refreshControl = UIRefreshControl()
    refreshControl.addTarget(self, action: #selector(refresh(_:)), for: .valueChanged)

    if #available(iOS 10.0, *) {
        tableView.refreshControl = refreshControl
    } else {
        tableView.backgroundView = refreshControl
    }
}

@objc func refresh(_ refreshControl: UIRefreshControl) {
    // Do your job, when done:
    refreshControl.endRefreshing()
}

关于ios - 在没有 UITableViewController 的情况下拉取刷新 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10291537/

相关文章:

ios - 具有 UITapGestureRecognizer 的 View 中的 UIButton

objective-c - 为什么 Objective-C 委托(delegate)通常被赋予属性分

ios - 动态改变UILabel的字体大小

objective-c - 如何等待异步调度的 block 完成?

objective-c - Objective-C 中的 NULL 与 nil

ios - 尝试将非属性列表对象设置为 NSUserDefaults

ios - 从 UIView 到 UIViewController?

objective-c - Objective-C 中的方法语法

ios - 在 Objective-C 中检查空字符串的正确方法是什么?

objective-c - 项目构建中的 CocoaPods 错误