【发布时间】:2019-09-02 20:57:10
【问题描述】:
这是我已经完成的代码:
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let deleteAction = UITableViewRowAction(style: .normal, title: "Delete") { (deleteAction, indexPath) in
self.deleteApm(currentIndex: Int) // here getting error
}
return [deleteAction]
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
cell.reSheduleBtn.addTarget(self, action: #selector(self.myReSheButt(_:)), for: .touchUpInside)
return cell
}
@IBAction func myReSheButt(_ sender: UIButton) {
reSheduleApm()
}
func reSheduleApm(){
let jsonDict = self.ArrayList[indexPath.row] as? [String:Any]
let appId:Int = jsonDict?["appId"] as! Int
let appId2 : Int = jsonDict?["appId"] as! Int
var appString = String(appId2)
let schedDay = jsonDict?["sDate"] as! String
let params: [String : String] = ["day":schedDay,"appId":appString]
let url = APIdata.URL_APP_RESHED
Alamofire.upload(
multipartFormData: { multipartFormData in
for (key, value) in params
{
multipartFormData.append((value.data(using: .utf8))!, withName: key)
}
},
to: url,
encodingCompletion: { encodingResult in switch encodingResult {
case .success(let upload, _, _):
upload.responseJSON { response in
print(response.value as Any)
// self.ArrayList.remove(at: indexPath.row)
// self.tblView.deleteRows(at: [indexPath], with: .fade)
}
case .failure(_):
break
}
})
}
在tableview单元格中,即使函数在外部写入,按钮操作也不起作用。
在UITableview中的editActionsForRowAt内部,函数无法在myReSheButt按钮操作内部调用。
而且函数不能在editActionsForRowAt里面调用也报错
如何解决?
【问题讨论】:
-
请正确格式化您的代码。目前,它不会编译,因为您有许多嵌套函数。您至少缺少一个右花括号。
-
选择器可以调用以@objc 开头的函数,除非你有充分的理由使用@IBAction,否则你可能不应该
标签: ios swift uitableview uibutton