我正在尝试添加扩展以向 TableView 添加下拉刷新。这是我正在关注的引用答案https://stackoverflow.com/a/33255722/6307359
我的代码抛出错误“无法识别的选择器发送到实例”
以下是我的代码。谁能调查一下并让我知道我哪里做错了?
提前发送。
扩展.swift
var refreshControl = UIRefreshControl()
public extension UIViewController
{
func addPullToRefresh(tableView: UITableView, refreshMethodName: String){
refreshControl.addTarget(self, action: Selector(refreshMethodName), for: .valueChanged)
if #available(iOS 10.0, *) {
tableView.refreshControl = refreshControl
} else {
tableView.addSubview(refreshControl)
}
}
func pullToRefreshEnd (){
refreshControl.endRefreshing()
}
}
ViewController.swift
override func viewDidLoad() {
super.viewDidLoad()
self.addPullToRefresh(tableView: statementsTable, refreshMethodName: "pullToRefresh")
}
// Pull to refresh implementation
func pullToRefresh() {
// some action here
self.pullToRefreshEnd()
}
最佳答案
我通过在 ViewController.swift 中的方法实现之前添加 @objc 来解决。无需其他更改。
// Pull to refresh implementation
@objc func pullToRefresh() {
// some action
self.pullToRefreshEnd()
}
关于ios - "Unrecognized selector sent to instance"用于扩展实现 TableView 的下拉刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52282286/