gpt4 book ai didi

ios - 在索引路径重新加载行不起作用

转载 作者:行者123 更新时间:2023-11-29 01:39:08 27 4
gpt4 key购买 nike

在我的社交媒体应用程序中,我有一个点赞按钮...

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
}

})

}
}

}

出于某种原因,当我在 indexPath 重新加载行时,like 标签也没有改变,这也是我在 cellForRowAtIndexPath 中设置按钮的地方...

dispatch_async(dispatch_get_main_queue()) {
if PFUser.currentUser()?.objectId != nil {
if (post["likers"] as! NSMutableArray).containsObject(PFUser.currentUser()!.objectId!) {
postCellObj.likeButton.setTitle("Unlike", forState: .Normal)

} else {
postCellObj.likeButton.setTitle("Like", forState: .Normal)

}

} else {
postCellObj.likeButton.setTitle("Like", forState: .Normal)

}
}

postCellObj.numberOfLikes.text = ((post["likers"] as! [String]).count - 1).description + " Likes"

有人知道这是怎么回事吗?谢谢!如果您需要更多信息,请告诉我! (:

最佳答案

如果我没看错你的代码,你在重新加载表格 View 单元格后删除了你的对象,而你正在重新加载你的单元格 - 标题仍然是“Unlike”,因为你的 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")

尝试断点它。

关于ios - 在索引路径重新加载行不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32620445/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com