добавьте тег для вашей кнопки в cellforRow, чтобы определить строку или конкретный объект
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "ACell", for: indexPath) as! ATableViewCell
cell.cancelBtn.tag = indexPath.row
cell.cancelBtn.addTarget(self, action: #selector(self.myButt(_:)), for: .touchUpInside)
}
, а также обработать действие как
@IBAction func myButt(_ sender: UIButton) {
let indexPath: IndexPath = IndexPath(row: sender.tag, section: 0)
deleteApm( currentIndexpath: indexPath)
}
как в deleteRow при вызове
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let deleteAction = UITableViewRowAction(style: .normal, title: "Delete") { (deleteAction, indexPath) in
self.deleteApm(currentIndexpath: indexPath)
}
return [deleteAction]
}
, наконец, создать общий метод для удаления вызова API
func deleteApm(currentIndexpath: IndexPath ) {
let jsonDict = self.ArrayList[currentIndexpath.row] as? [String:Any]
let Id:Int = jsonDict?["appointId"] as! Int
let Id2 : Int = jsonDict?["appointId"] as! Int
let param : [String : String] = ["pid": {String(Id2)}()]
let headers = ["Content-Type": "application/x-www-form-urlencoded"]
// "http://192.168.1.45:8080/zybrodental/patientApp/patientAppDeleteMultipleAppointment"
Alamofire.request(APIMetadata.URL_DELETE_APPOINT, method: .post, parameters: param, encoding: URLEncoding.httpBody, headers: headers).responseJSON { (response:DataResponse<Any>) in
switch(response.result) {
case.success(let data):
print("success",data)
self.ArrayList.remove(at: currentIndexpath.row)
self.yourtableViewName.deleteRows(at: [currentIndexpath], with: .fade)
case.failure(let error):
print("Not Success",error)
}
}
}