我试图在表视图单元格上滑动删除,但是在刷过该单元格数次后,只有它被删除。如何使其顺利工作(一次尝试滑动和删除)?我的代码在这里:
SELECT COUNT(*) AS `doubles` FROM [table] GROUP BY `Kanji` HAVING `doubles` > 1;
答案 0 :(得分:1)
首先,我想指出你在错误的地方展示警报。成功后,您在API上进行删除调用,询问他或她是否想要确认。你必须在致电删除之前询问它
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
var bId = Helper.businessId as String
let param = ["id" : bId] as! [String : AnyObject]
if editingStyle == .delete{
print(Helper.memId)
print("Deleted")
var myDictionary = self.List[indexPath.row] as! NSDictionary
var bId : String!
if myDictionary.allKeys.count>0
{
bId = myDictionary["id"] as! String
}
var bb = bId as String
if editingStyle == .delete{
print(Helper.memId)
print("Deleted")
let myAlert = UIAlertController(title:"Alert", message: "Do You want to delete",preferredStyle:UIAlertControllerStyle.alert)
let okAction = UIAlertAction(title:"Ok",style:UIAlertActionStyle.default,handler:{ (action: UIAlertAction!) in
// here you can call the delete if user accepts
Alamofire.request("http://api.noattabeta.com/api/v1/user/current/memberships/\(bb)", method: .delete, headers: ["Authorization":Helper.token]).responseString
{response in
print("In Response")
switch response.result {
case .success:
DispatchQueue.main.async {
// remove from your local array e.g
self.dataModel.remove(at: indexPath.row)
// Delete the row before you reload the tableView
self.tableView.deleteRows(at: [indexPath], with: .automatic)
// Now reload your tableView
self.tableView.reloadData()
}
case .failure(let error):
print(error)
})
myAlert.addAction(okAction)
let cancelAction = UIAlertAction(title:"Cancel",style:UIAlertActionStyle.default,handler:{ (action: UIAlertAction!) in
self.tableView.reloadData()
})
myAlert.addAction(okAction)
myAlert.addAction(cancelAction)
self.present(myAlert, animated: true, completion: nil)
}