我知道这是一个常见问题,但我无法找到解决方案是否我搜索了几个小时,所以我决定打开一个新问题。我得到“[UIRefreshControl copyWithZone:]:无法识别的选择器发送到实例0x102029400”问题。当我第一次打开视图时。出现加载但它不符合表格。但是,当我检查模型类时,它从数据库中获取值。
在viewcontroller声明中;
model.delegate = self
model.refresh_history(sensor_name: send_item)
// Set up a refresh control.
mTableView.refreshControl = UIRefreshControl()
mTableView.refreshControl?.addTarget(model, action: #selector(model.refresh_history), for: .valueChanged)
代表;
extension ChooseHistoryViewController: ModelDelegate {
func modelUpdated() {
mTableView.refreshControl?.endRefreshing()
mTableView.reloadData()
}
func errorUpdating(_ error: NSError) {
let message: String
if error.code == 1 {
message = "Error"
} else {
message = error.localizedDescription
}
let alertController = UIAlertController(title: nil,
message: message,
preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Dismiss", style: .default, handler: nil))
present(alertController, animated: true, completion: nil)
}
}
和我的模特课;
protocol ModelDelegate {
func errorUpdating(_ error: NSError)
func modelUpdated()
}
class Model{
var user: User
static let sharedInstance = Model()
var sensor_ecg: Sensor_ECG?
var delegate: ModelDelegate?
var history: [String] = []
init()
{
user = User()
}
@objc func refresh_history(sensor_name: String){
let parameters: Parameters = ["q" : "{\"member_id\" :\"\(user.id!)\"}", "apiKey": "2ABdhQTy1GAWiwfvsKfJyeZVfrHeloQI"]
Alamofire.request("https://api.mlab.com/api/1/databases/mysignal/collections/\(sensor_name)", method: .get, parameters: parameters,encoding: URLEncoding.default, headers: nil).responseJSON{ response in
let json = JSON(data: response.data!)
print(json)
if(response.response == nil) {
return
}
let history = json[0]["date"].string!
print(history)
}
DispatchQueue.main.async {
self.delegate?.modelUpdated()
}
}
答案 0 :(得分:0)
您需要更改
如果您将方法声明为“refresh_history:”(即带参数),则需要在“#selector”位添加冒号。
换句话说,一行改变一个字符:
mTableView.refreshControl?.addTarget(model, action: #selector(model.refresh_history(sensor_name:)), for: .valueChanged)