我试图从Parse中删除一行,但我不知道该怎么做。我有一个tableView,其中一些名称取自Parse,当我使用commitEditingStyle函数时,我想从Parse中删除该名称。 我写了这段代码,但它不完整,我不知道如何完成它:
if (editingStyle == UITableViewCellEditingStyle.Delete) {
var friendSelected:String = friendsArray[indexPath.row]
friendsArray.removeAtIndex(indexPath.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
// Remove From Parse
var tempArrayFriend:[String] = [String]()
var query = PFQuery(className:"Friend")
query.whereKey("UserKey", containsString: PFUser.currentUser()?.username)
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
for friend in objects! {
let friendFromParse:String? = (friend as! PFObject)["Friend"] as? String
// Aggiungo i voti all'array corrispondete
if friendFromParse != nil {
tempArrayFriend.append(friendFromParse!)
friend.removeObjectForKey(friendSelected)
} else {
// Log details of the failure
}
}
}
我想从Parse中删除一行,其中键是PFUser.username!谢谢,我希望你能帮助我!
答案 0 :(得分:0)
我认为你让它变得比它需要的复杂得多。试试这个:
if (editingStyle == UITableViewCellEditingStyle.Delete) {
var friendSelected:String = friendsArray[indexPath.row]
friendsArray.removeAtIndex(indexPath.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
// Remove From Parse
var query = PFQuery(className:"Friend")
query.whereKey("UserKey", containsString: PFUser.currentUser()?.username)
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
for friend in objects! {
friend.deleteInBackgroundWithBlock(nil)
}
} else {
// Log details of the failure
}
}
}