【发布时间】:2015-04-15 03:43:22
【问题描述】:
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)
}
}
// 以上部分是我的IBAction 的tableviewcell 中upvote button cell 的委托方法。
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 按钮时。但不幸的是,它不会在一个人重新登录系统后点赞的帖子上显示活跃的点赞图片。
【问题讨论】:
标签: swift parse-platform nsarray