我试图通过解析在我的应用程序上实现类似于Facebook或Instagram的按钮功能。我尝试使用下面的代码,它的工作原理。当用户点击一个对象上的按钮(或者在我的情况下为消息)时,类似的情况会上升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)")
}
也许你可以尝试使用数组或关系来跟踪所有的每个用户都有职位的喜欢,然后创建后单元格时,检查数组或关系是否已经包含该帖子。如果是这样,请防止用户再次喜欢它。 – Acoop
这是我在Parse上做的事吗? – Cooni