ios - UITableView 不显示标签,也不显示单元格

标签 ios iphone swift cocoa-touch parse-platform

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

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

最佳答案

您忘记配置 tableview 数据源。

class DetailViewContoller: UIViewController, UITableViewDelegate, UITableViewDataSource, UITextViewDelegate {

...
...
...

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

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

关于ios - UITableView 不显示标签,也不显示单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32430167/

相关文章:

objective-c - 获取发送到已释放实例的 [Not a type retain] 和 [Not a type class] 消息

ios - URL 在 UIWebView 和 WKWebView 之间停止加载。仅限 iOS 11

ios - 如何使用 CoreData 结果快速排序并显示在 UITableview 的正确部分

iphone - 如何取消 iOS 后台的所有 NSURLConnections

iphone - 为推送通知配置 ‘App store distribution provision profile’ 的步骤

iphone - 如何隐藏导航栏后退按钮

iOS 10 时区格式问题,日期创建为 timeIntervalSince1970

ios - 在单个 View 应用程序中使用 sprite kit

javascript - 如何使用 phonegap/javascript iOS 读取设备 token (parse.com)

ios - H.264 .mov 文件上的一帧后 AVAssetReader 失败