ios - tableView 中不显示评论

标签 ios iphone swift cocoa-touch parse-platform

在我正在开发的应用程序中,它允许用户在主时间线上发帖,而其他用户可以对该用户的帖子发表评论,所以我一直试图在 tableView 中显示评论,但它没有显示。我已经确认数据正在发布以进行解析,因此它按预期工作,但在显示评论时,我似乎无法让它工作。我正在使用此功能来显示评论:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    var cell = tableView.dequeueReusableCellWithIdentifier("commentCell", forIndexPath: indexPath) as! CommentTableViewCell
    cell.commentLabel?.text = comments![indexPath.row]

    return cell
}

我的代码有什么问题吗?还是有其他方式显示评论?

最佳答案

检索评论的代码在哪里?确保在 for 循环之后调用“self.tableView.reloadData()”。

我通常从解析中检索信息的方式是这样的:

    func query() {
    var query = PFQuery(className: "comments")
    query.orderByDescending("createdAt")
    query.findObjectsInBackgroundWithBlock { (caption2: [AnyObject]?, erreur: NSError?) -> Void in
        if erreur == nil {
            // good
            for caption in caption2! {
                   self.comments.append(caption["<YOUR COLUMN NAME WHERE COMMENT IS STORED IN PARSE HERE>"] as! String)



            }
            self.tableView.reloadData()
        }
        else {
            // not good
        }
    }
   }

将这个函数添加到你的类中。然后改变这个:

     func reply() {
post?.addObject(commentView!.text, forKey: "comments")
post?.saveInBackground()
if let tmpText = commentView?.text {
    comments?.append(tmpText)
}
commentView?.text = ""
println(comments?.count)
self.commentView?.resignFirstResponder()
self.commentTableView.reloadData()
 }

为此:

      func reply() {
post?.addObject(commentView!.text, forKey: "comments")
post?.saveInBackground()
if let tmpText = commentView?.text {
    comments?.append(tmpText)
}
commentView?.text = ""
println(comments?.count)
self.commentView?.resignFirstResponder()
self.query
 }

关于ios - tableView 中不显示评论,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32428873/

相关文章:

ios - 无法在聊天 TableView 中创建带有聊天气泡的自定义消息 lbl。 (全部以编程方式)

arrays - Swift 和 NSCoding : Encoding an array of objects conforming to a class-only protocol

ios - 我的 sqlite 查询(更新)在 iOS 中看起来不工作

iphone - 访问类中的常量而不在 Objective C 中创建类的实例

ios - 在 Parse 中获取特定行

iPhone 应用程序代码签名

swift - 重写类之外的函数

IOS UICollectionView Register nib for UICollectionViewCell 不工作

iOS:自动布局中的多行 UILabel

ios - iOS 13 中出现蓝牙权限请求警报,但应用程序不使用蓝牙