无需UITableViewController即可刷新UITableView [英] Pull to refresh UITableView without UITableViewController

查看:187
本文介绍了无需UITableViewController即可刷新UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在UIViewController中的UITableView中实现一个pull to refresh功能。我不能使用UITableViewController,因为我希望UITableView在视图控制器中是一个较小的子视图,上面还有一些其他东西。我认为这是可能的,但有没有人看到它的实现?

I'm trying to implement a pull to refresh feature in a UITableView within a UIViewController. I can't use a UITableViewController because I want the UITableView to be a smaller subview in the view controller, with some other stuff above it. I assume this is possible, but has anyone seen an implementation of it?

推荐答案

直接向<$ c添加刷新控件$ c> UITableView ,不使用 UITableViewController

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()
}

这篇关于无需UITableViewController即可刷新UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆