2015-09-07 79 views
0

我有一個數組,它保存用戶回覆帖子的評論,他們保存在Parse.com中,但似乎當我嘗試在tableView中顯示它們時,它們不是出現。這是我用來在tableView中顯示註釋的內容。UITableView不顯示標籤,也沒有單元格

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

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

    return cell 
} 

我已經嘗試了一些其他的代碼變化和一些其他帖子在這裏試圖找到答案,但仍然沒有運氣。 我可以確認數據保存在Parse中,但似乎沒有顯示在應用程序中。我究竟做錯了什麼?

回答

1

你忘記了配置tableview數據源。

class DetailViewContoller: UIViewController, UITableViewDelegate, UITableViewDataSource, UITextViewDelegate { 

... 
... 
... 

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

要使用tableview你必須配置tableview委託和數據源。

+0

我試圖添加它,它給了我以下錯誤:**使用未聲明的類型'UITableViewDatasource'**我必須在使用dataSource之前導入其他內容嗎? –

+0

http://stackoverflow.com/questions/28017622/why-the-use-of-undeclared-type-uitableview-happened-in-swift。可能導入UIKit解決這個問題就像這個問題。 – merge

+0

DataSource的's'是小寫字母,在我將它改爲大寫字母后,它解決了這個問題。現在它工作正常。它還顯示評論。我一直試圖弄清楚這一點。你拯救了一天!謝謝! –

相關問題