【问题标题】:UITableView is not displaying labels, nor cellsUITableView 不显示标签,也不显示单元格
【发布时间】:2015-09-07 01:59:16
【问题描述】:

我有一个包含用户回复帖子的 cmets 的数组,它们保存在 Parse.com 中,但是当我尝试在 tableView 中显示它们时,它们似乎没有显示出来。这是我用来在 tableView 中显示 cmets 的。

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 中,但它似乎没有显示在应用程序中。我做错了什么?

【问题讨论】:

    标签: ios iphone swift cocoa-touch parse-platform


    【解决方案1】:

    您忘记配置 tableview 数据源。

    class DetailViewContoller: UIViewController, UITableViewDelegate, UITableViewDataSource, UITextViewDelegate {
    
    ...
    ...
    ...
    
    override func viewDidLoad() {
        super.viewDidLoad()
        commentTableView.delegate = self
        commentTableView.dataSource = self
    

    要使用 tableview,您必须配置 tableview 委托和数据源。

    【讨论】:

    • 我试图添加它,它给了我以下错误:使用未声明的类型'UITableViewDatasource'在使用数据源之前我必须导入其他东西吗?
    • stackoverflow.com/questions/28017622/… .Maybe import UIKit 可以像这个问题一样解决这个问题。
    • DataSource 的 's' 是小写的,我把它改成大写后就解决了这个问题。它现在工作正常。它还显示 cmets。我整天都在想办法解决这个问题。你拯救了这一天!谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多