ios - PFTableViewCell 不改变 labelText

标签 ios parse-platform swift ios8

下面的代码应该从传递到 cellForRowAtIndexPath 的 PFObject 中获取名称字段,并将 textLabel.text 字段设置为名称(即 tableView 行可能读取“sneeze1”)。我可以使用 heightForRowAtIndexPath 方法更改每一行的高度,还可以使用正确的字段查看对 cellForRowAtIndexPath 的正确调用次数(在我的特定情况下,3 行加载到 Parse 的数据浏览器上的一个类中),但我可以'获取要更改的 textLabel.text。

在 textLabel 可以更改其文本之前是否需要完成其他一些步骤?

override func tableView(tableView: UITableView!, heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat {
    return 60
}

override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!, object: PFObject!) -> PFTableViewCell! {
    var cellIdentifier = "EventCell"

    var cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as? PFTableViewCell

    if !cell {
        cell = PFTableViewCell(style: .Subtitle, reuseIdentifier: cellIdentifier)
    }

    var name = object["name"] as? String
    cell!.textLabel.text = name
    println("textLabel: \(cell!.textLabel.text)" + "  name: \(name)")

    return cell
}

最佳答案

您必须使用原始委托(delegate)签名,否则您的方法将不会被调用。而不是

override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!, object: PFObject!) -> PFTableViewCell!

使用

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

关于ios - PFTableViewCell 不改变 labelText,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24522979/

相关文章:

swift - 如何禁用 ARCoachingOverlayView 的自动激活?

ios - 如何以编程方式将顶部约束更改为布局中的另一个项目

ios - UICollectionView刷新问题

Objective-c 重构,代码归属于哪里?

ios - 在 block 方法IOS中读取多个数据

swift - 在 Swift 中使用 Cell Tags 和 objectForKey

javascript - 在云代码中使用 Promise

ios - 为什么 __weak 变量没有在自动释放池中注册?

iphone - 检查字符串是否与数组中的任何值匹配?

ios - 如果单击 UISearchBar,则更改 UITableView 位置 : [using ModernSearchBar]