tableView显示相同的单元格

时间:2015-07-06 15:39:26

标签: ios uitableview parse-platform pfquery

我正在创建一个社交应用程序,我想在其中显示用户的评论。 现在,有时当我打开VC时,它将显示相同的单元格两次(有时甚至更多)。见下图:

Storyboard and Realtime

奇怪的是当我'打印'CellForRowAtIndexPath中'PFQuery Block'的对象时,它会显示println 2次或更多次。我不知道这是怎么来的......可能与CachePolicy有关吗?

P.s:在同一问题上找不到答案:Here

}else {
        let commentCell:commentTableViewCell = tableView.dequeueReusableCellWithIdentifier("commentCell") as commentTableViewCell

        let commentIndex:NSIndexPath = NSIndexPath(forRow: indexPath.row-2, inSection: 0)
        let comment:PFObject = userComments.objectAtIndex(commentIndex.row) as PFObject

        // Comment Label
        commentCell.commentLabel.text = comment.objectForKey("content") as String!

        // Datum
        let date:NSDate = NSDate(timeIntervalSinceNow: 1)
        let string:NSString = date.timeAgoSinceDate(comment.createdAt)
        commentCell.datumLabel.text = string

        // Load each comment after row: 1
        var userCommentImage:PFQuery = PFUser.query()
        userCommentImage.whereKey("objectId", equalTo: comment.objectForKey("gebruiker").objectId)
        userCommentImage.findObjectsInBackgroundWithBlock({
            (objects:[AnyObject]!, error:NSError!) -> Void in
            if error == nil{

                println("How many reactions are there? = \(objects.count)")

                let user:PFUser = (objects as NSArray).firstObject as PFUser
                commentCell.userLabel.text = user.username

                // Profile Image
                let profileImage:PFFile = user["profileImage"] as PFFile
                profileImage.getDataInBackgroundWithBlock({
                    (imageData:NSData!, error:NSError!) -> Void in
                    if error == nil{
                        let image = UIImage(data: imageData)
                        commentCell.userImageView.image = image

                        UIView.animateWithDuration(0.5, animations: {
                            commentCell.userImageView.alpha = 1
                            commentCell.userLabel.alpha = 1
                            commentCell.datumLabel.alpha = 1
                            commentCell.commentLabel.alpha = 1
                        })
                    }
                })
            }
        })

        return commentCell
    }

0 个答案:

没有答案