var showTopicLikeNumber = PFUser.query()
showTopicLikeNumber.whereKey("liked", equalTo: topic.objectId)
showTopicLikeNumber.findObjectsInBackgroundWithBlock({
(objects:[AnyObject]!,error:NSError!)->Void in
if (error == nil){
let liked:NSArray = objects as NSArray
cell.upvoteButton.setTitle("\(liked.count)", forState: UIControlState.Normal)
}
//以上的部分是用於顯示像數,和它的作品。解析:不能從後發現喜歡標識,以使喜歡的圖像
func topicTableViewCellDidTouchUpvote(cell: TopicTableViewCell, sender: AnyObject) {
if PFUser.currentUser() != nil{
let senderButton:UIButton = sender as UIButton
var topicLiked:PFObject =
timelineTopicData.objectAtIndex(senderButton.tag) as PFObject
println(topicLiked.objectId)
PFUser.currentUser().addUniqueObject(topicLiked.objectId, forKey: "liked")
PFUser.currentUser().save()
senderButton.setImage(UIImage(named:"icon-upvote-active"), forState: UIControlState.Normal)
}
else{
performSegueWithIdentifier("loginTopicSegue", sender: self)
}
}
//以上部分是我從tableviewcell給予好評鈕釦電池的IBAction爲的委託方法。
var showTopicUpvoteEnable = PFQuery(className: "Topics")
showTopicUpvoteEnable.whereKey("objectId", equalTo:PFUser.currentUser().valueForKey("liked"))
showTopicUpvoteEnable.findObjectsInBackgroundWithBlock({
(objects:[AnyObject]!,error:NSError!)->Void in
if error == nil{
cell.upvoteButton.setImage(UIImage(named:"icon-upvote-active"), forState: UIControlState.Normal)}
else{
cell.upvoteButton.setImage(UIImage(named: "icon-upvote"), forState: UIControlState.Normal)}
})
//我想表明的積極喜歡的圖像,當用戶已經喜歡上了一個帖子,雖然它能夠顯示,因爲我在IBAction爲使喜歡的圖像時,按下按鈕給予好評。但不幸的是,它不會在帖子重新登錄系統後喜歡的帖子上顯示活躍的upvote圖像。
如果這個回答你的問題,請接受它 – SanitLee
解決了它...謝謝Sanit Lee –