2015-09-06 90 views
1

在我正在處理的應用程序中,它允許用戶發佈主時間軸上,其他用戶可以評論該用戶的帖子,所以我一直試圖在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 
} 

是什麼問題我的代碼?還是有另一種方式來顯示評論?

回答

0

原來我錯過了:

UITableViewDataSource 
在我的課

,所以這個固定:

class DetailViewContoller: UIViewController, UITableViewDelegate, UITableViewDataSource, UITextViewDelegate { 

... 
... 
... 

override func viewDidLoad() { 
super.viewDidLoad() 
commentTableView.delegate = self 
commentTableView.dataSource = self 
0

其中是檢索評論的代碼?確保你在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 
} 
+0

我剛加了我全班 –

+0

什麼循環之後? –

+0

好吧,我添加了該函數,並修改了'reply()'函數,但是在self.comments.append(caption [「comments」] as String)中出現錯誤,說**不能使用參數列表類型的字符串**和錯誤在這裏:'self.tableView.reloadData()'與**不能調用reloadData沒有參數** –