个人开源项目,基于系统UIRefreshControl的自定义下拉刷新控件,极易上手。
导入ZFRefresh文件夹,在tableViewController中写如下三行代码:
class ViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
// 1.创建刷新控件,添加下拉监听
refreshControl = ZFRefreshControl(navBar: (navigationController?.navigationBar)!)
refreshControl?.addTarget(self, action: "loadData", forControlEvents: .ValueChanged)
}
@objc private func loadData() {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(1.5 * Double(NSEC_PER_SEC))), dispatch_get_main_queue()) { () -> Void in
// 2.网络请求成功或者失败后,结束刷新
self.refreshControl?.zf_endRefreshing(10)
}
}
}
受到@极客江南的启发,非常感谢!
We welcome any contributions.
ZFRefresh is available under the MIT license. See the LICENSE file for more info.