scrollview中的Refreshcontrol无法在swift中运行

问题描述 投票:0回答:2

我的视图中有可滚动的内容。我想在其中添加pull来刷新。我尝试添加但不会触发操作。

我尝试了很多方法并重新搜索,但没有一个适合我。我将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()
}
ios swift iphone uiscrollview pull-to-refresh
2个回答
0
投票

选择你的tablviewcontroller转到检查器查找刷新选择启用goto文档大纲并选择刷新控制控件拖动或右键单击(按住)拖动到你的控制器文件并调用它上面的函数来刷新数据

在tableview上没有它


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

    }
}
© www.soinside.com 2019 - 2024. All rights reserved.