以下是我在tableView中删除会话行的代码:
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
// Get other user id
let userObjectId = userIds[indexPath.row]
// query db for that id
let matchesQuery = PFUser.query()
matchesQuery?.whereKey("objectId", contains: PFUser.current()?.objectId)
matchesQuery?.whereKey("accepted", contains: userObjectId)
matchesQuery?.findObjectsInBackground { (objects, error) in
if let users = objects {
for user in users {
if let theUser = user as? PFUser {
if let accepptedUserIds = theUser["accepted"] as? [String] {
for acceptedUserId in accepptedUserIds {
for id in self.userIds {
if id == acceptedUserId {
self.userIds = accepptedUserIds.filter{$0 != userObjectId}
PFUser.current()?["accepted"] = self.userIds
PFUser.current()?.saveInBackground(block: { (success, error) in
if success {
if self.images.count == 1 {
self.images.remove(at: indexPath.row) // Line raising error
self.tableView.reloadData()
} else {
self.images.remove(at: indexPath.row)
self.tableView.deleteRows(at: [indexPath], with: .left)
}
} else {
print("There was an error removing the match. Please try again.")
}
})
}
}
}
}
}
}
}
}
}
}
@IBAction func backTapped(_ sender: Any) {
dismiss(animated: true, completion: nil)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.view.endEditing(true)
}
Eveytime我尝试在表视图中删除一行我遇到崩溃致命错误,超出范围,有人可以告诉我如何修复我的代码吗?
提前致谢!
造成问题的一行是: