我想要创建一个将refreshControll添加到UITableView的函数。
我遇到的问题是#selector
extension UITableView{
func refreshTableView(callFunction: #selector()){
refreshControl = UIRefreshControl()
refreshControl?.attributedTitle = NSAttributedString(string: "Pull to refresh")
refreshControl?.addTarget(self, action: #selector(callFunction), for: .valueChanged)
self.addSubview(refreshControl!)
}
}当我使用这个函数时,我想指定要调用哪个函数。
这有可能吗?
发布于 2018-07-10 15:58:37
#selector(...)是Selector类型的表达式,因此您的方法应该接受Selector对象并直接将其传递给action:参数。
extension UITableView {
func refreshTableView(callFunction: Selector) {
// ...
refreshControl?.addTarget(self, action: callFunction, for: .valueChanged)
// ...
}
}
myTableView.refreshTableView(callFunction: #selector(whatever))https://stackoverflow.com/questions/51269660
复制相似问题