下面的代码应该从传递到 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/