在我的社交媒体应用中,我有一个类似的按钮......
selectReviews
出于某些原因,当我在indexPath上重新加载行时,like标签也没有改变,这也是我在cellForRowAtIndexPath中设置按钮的地方......
var likers = [String]()
func like(sender: UIButton) {
var buttonPosition: CGPoint = sender.convertPoint(CGPointZero, toView: self.table)
var indexPath: NSIndexPath = self.table.indexPathForRowAtPoint(buttonPosition)!
testConnection()
var post = posts[indexPath.row]
if sender.currentTitle == "Unlike" {
dispatch_async(dispatch_get_main_queue()) {
self.table.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
}
sender.enabled = false
post.removeObject(PFUser.currentUser()!.objectId!, forKey: "likers")
post.saveInBackgroundWithBlock({ (success, error) -> Void in
if success == true {
sender.enabled = true
}
if error != nil {
sender.enabled = true
}
})
} else {
dispatch_async(dispatch_get_main_queue()) {
self.table.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
}
sender.enabled = false
dispatch_async(dispatch_get_main_queue()) {
post.addUniqueObject(PFUser.currentUser()!.objectId!, forKey: "likers")
post.saveInBackgroundWithBlock({ (success, error) -> Void in
if success == true {
sender.enabled = true
}
if error != nil {
sender.enabled = true
}
})
}
}
}
有谁知道可能会发生什么?谢谢!如果您需要更多信息,请告诉我! (:
答案 0 :(得分:1)
如果我正在正确阅读您的代码,则在重新加载表格视图单元格时,您正在重新加载单元格时删除对象 - 标题仍然是“不同”,因为您的objectId仍然存在于您的数组中:
(1)
if sender.currentTitle == "Unlike" {
dispatch_async(dispatch_get_main_queue()) {
self.table.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
}
...
(2)
if (post["likers"] as! NSMutableArray).containsObject(PFUser.currentUser()!.objectId!) {
postCellObj.likeButton.setTitle("Unlike", forState: .Normal)
}
(3)
...
post.removeObject(PFUser.currentUser()!.objectId!, forKey: "likers")
尝试破坏它。
答案 1 :(得分:0)
我能够通过将其放入方法
来解决问题if success == true {
}
通过做
sender.title = "Like" //Or unlike for the else statement
当我大声说出来时,我会接受这个作为答案,但是如果有人知道怎么做,我很想知道如何停止那个大动画
table.reloadRowsAtIndexPaths([indexPath], withRoAnimation: .None)
因为即使使用.None,它仍然看起来不那么好。到目前为止,我能找到的唯一答案是刷新整个表格,但我不想这样做。