[英]In tableview cell, button action not working
Here is the code I've already done:这是我已经完成的代码:
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
}
})
}
In tableview cell, button action not working even if the function writes outside.在 tableview 单元格中,即使函数在外部写入,按钮动作也不起作用。
Inside editActionsForRowAt
in UITableview
the function cannot call inside the myReSheButt
button Action.在
editActionsForRowAt
中的UITableview
内部,该函数无法在myReSheButt
按钮操作中调用。
And the function cannot call inside the editActionsForRowAt Also getting error并且该函数无法在 editActionsForRowAt 内部调用也出现错误
How to solve this?如何解决这个问题?
pass your tag in cell for row在行的单元格中传递您的标签
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
cell.reSheduleBtn.tag = indexPath.row
cell.reSheduleBtn.addTarget(self, action: #selector(self.myReSheButt(_:)), for: .touchUpInside)
return cell
}
and handle the action as并将动作处理为
@objc func myReSheButt(_ sender: UIButton) {
reSheduleApm(currentIndex: sender.tag)
}
ans pass your currentIndex to your reSheduleApm ans 将您的 currentIndex 传递给您的 reSheduleApm
func reSheduleApm(currentIndex: Int){
let jsonDict = self.ArrayList[currentIndex] 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
}
})
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.