【发布时间】:2015-11-01 22:20:46
【问题描述】:
我正在尝试通过解析在我的应用程序上实现类似 facebook 或 instagram 的点赞按钮功能。我尝试在下面使用此代码并且它有效。当用户点击对象上的按钮(或在我的情况下为消息)时,like 增加 1 点。然而,当用户退出应用程序并启动它时,他们可以再次喜欢同一个对象,这意味着他们可以随意喜欢多次。我是否需要在此代码中编辑某些内容或尝试完全不同的方法?
@IBAction func likeButton(sender: UIButton) {
sender.enabled = false
sender.userInteractionEnabled = false
sender.alpha = 0.5
//get the point in the table view that corresponds to the button that was pressed
//in my case these were a bunch of cells each with their own like button
let hitPoint = sender.convertPoint(CGPointZero, toView: self.tableView)
let hitIndex = self.tableView.indexPathForRowAtPoint(hitPoint)
let object = objectAtIndexPath(hitIndex)
//this is where I incremented the key for the object
object!.incrementKey("count")
object!.saveInBackground()
self.tableView.reloadData()
NSLog("Top Index Path \(hitIndex?.row)")
}
【问题讨论】:
-
也许您可以尝试使用数组或关系来跟踪每个用户喜欢的所有帖子,然后在创建帖子单元格时,检查数组或关系是否已经包含该帖子.如果是,请阻止用户再次点赞。
-
这是我在 Parse 上做的事情吗?
标签: ios swift parse-platform pfquery