我的视图中有可滚动的内容。我想添加拉动以刷新它。我尝试添加,但未触发操作。
我尝试了多种方式并也进行了重新搜索,但均无济于事。我将iOS 10作为最低部署目标。
Try1:
let refreshControl = UIRefreshControl()
self.scl_view.alwaysBounceVertical = true
refreshControl.addTarget(self, action: #selector(pullToRefresh(_:)), for: .valueChanged)
scl_view.addSubview(refreshControl)
Try2:
let refreshControl = UIRefreshControl()
self.scl_view.alwaysBounceVertical = true
refreshControl.addTarget(self, action: #selector(pullToRefresh(_:)), for: .valueChanged)
scl_view.refreshControl = refreshControl
// MARK:-刷新控件
@objc func pullToRefresh(_ refreshControl: UIRefreshControl) {
// Update your conntent here
self.setupData()
//refreshControl.endRefreshing()
}
答案 0 :(得分:0)
选择您的tablviewcontroller 转到检查器 查找刷新选择已启用 转到文档大纲并选择刷新控件 控制拖动或右键单击(按住)拖动到您的控制器文件并在其上调用函数以刷新数据
在表视图上不可用
答案 1 :(得分:0)
var refreshControl = UIRefreshControl()
override func viewDidLoad() {
super.viewDidLoad()
collectionView.delegate = self
collectionView.dataSource = self
// Add Refresh Control to collection View
if #available(iOS 10.0, *) {
collectionView.refreshControl = refreshControl
} else {
collectionView.addSubview(refreshControl)
}
refreshControl.tintColor = UIColor(red:0.25, green:0.72, blue:0.85, alpha:1.0)
// Configure Refresh Control
refreshControl.addTarget(self, action: #selector(fetchData(_:)), for: .valueChanged)
}
@objc private func fetchData(_ sender: Any) {
DispatchQueue.main.async {
//Fuction which you want to call
self.refreshControl.endRefreshing()
}
}