您好,我正在从 tableview 中删除行,它对我来说工作正常,我已成功删除,但删除后我遇到如下崩溃和错误
错误
Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
在这里我向你展示我的代码我崩溃的地方
代码
@IBAction func btnDeleteYesTapped(_ sender: UIButton) {
let preferences = UserDefaults.standard
let uid = "u_id"
let acTkn = "acc_tkn"
let u_ID = preferences.object(forKey: uid)
let A_Token = preferences.object(forKey: acTkn)
let params = ["user_id": u_ID!, "access_token": A_Token!,"property_id": propertyID!,"occupants_id": oCCID!]
print(params)
Alamofire.request(propertyoccupantsdelete, method: .post, parameters: params).responseJSON
{
response in
print(response)
let result = response.result.value
print(response)
let data = result as! [String : AnyObject]
let status = data["success"] as! String
if status == "1"{
let buttonPosition : CGPoint = (sender as AnyObject).convert((sender as AnyObject).bounds.origin, to: self.tblOccList)
let indexPath = self.tblOccList.indexPathForRow(at: buttonPosition)! //At Here I am Getting crash
self.occuPantsData.remove(at: indexPath.row)
self.tblOccList.deleteRows(at: [indexPath], with: .fade)
Toast(text: data["message"] as? String).show()
}else{
Toast(text: data["message"] as? String).show()
}
}
}
我无法理解为什么我会崩溃,谁能告诉我我做错了什么
显示对话的代码
@objc func handleLongPress(longPressGesture:UILongPressGestureRecognizer) {
let p = longPressGesture.location(in: self.tblOccList)
let indexPath = self.tblOccList.indexPathForRow(at: p)
if indexPath == nil {
print("Long press on table view, not row.")
}
else if (longPressGesture.state == UIGestureRecognizer.State.began) {
print("Long press on row, at \(indexPath!.row)")
let id = occuPantsData[indexPath!.row].id
print(id)
self.oCCID = id
self.viewDeletePopUp.isHidden = false
}
}