在我的应用程序上有一个喜欢帖子的选项。我使用我分配给带有 .addTarget 的点赞按钮的这个函数将用户的 objectId 添加到一个数组中,该数组被计算以确定有多少点赞。我想知道如何从数组中删除一个名字,就像有人想对帖子点赞一样。
func like(sender: AnyObject) {
var buttonPosition: CGPoint = sender.convertPoint(CGPointZero, toView: self.table)
var indexPath: NSIndexPath = self.table.indexPathForRowAtPoint(buttonPosition)!
var postsQuery = PFQuery(className: "Post")
postsQuery.whereKey("message", equalTo: messages[indexPath.row])
postsQuery.findObjectsInBackgroundWithBlock { (posts, error) -> Void in
if let posts = posts {
for post in posts {
post.addUniqueObject(PFUser.currentUser()!.objectId!, forKey: "likers")
println(self.likesArray)
post.saveInBackground()
self.table.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
}
}
}
}
最佳答案
当您使用 addUniqueObject:forKey:
添加到数组时,您可以使用 removeObject:forKey:
从数组中删除然后保存。
关于ios - 如何从解析数组中删除项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32544536/