【发布时间】:2015-06-15 14:07:00
【问题描述】:
我正在尝试使用字幕样式在单元格标题中获取两个文本。我试过 "cell.textLabel!.text = data.valueForKeyPath("divelocation, divenumber") as?String" 没有运气。
谁能帮忙?谢谢
override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell {
// Configure the cell...
let CellID: NSString = "Cell"
var cell: UITableViewCell = tableView?.dequeueReusableCellWithIdentifier(CellID as String)! as! UITableViewCell
if let ip = indexPath{
var data: NSManagedObject = myList[ip.row] as! NSManagedObject
cell.textLabel!.text = data.valueForKeyPath("divelocation, divenumber") as? String
var ddate = data.valueForKeyPath("divedate") as! String
var dnumber = data.valueForKeyPath("divenumber") as! String
cell.detailTextLabel!.text = "\(dnumber) date: \(ddate)"
}
return cell
}
【问题讨论】:
-
发生了什么?您是否正确看到了
textLabel,而只有detailTextLabel没有出现?您在原型单元格中指定了哪种单元格类型? -
如果我有 cell.textLabel!.text = data.valueForKeyPath("divelocation") 作为?字符串然后一切正常,我只想在潜水位置旁边添加潜水编号。我在原型单元格中使用字幕单元格
-
@Scubadivingfool 你的关键路径不应该是“divelocation.divenumber”吗?
-
好的,让我们退后一步。你问题的标题说副标题有问题(即
detailTextLabel)。但是在阅读了您的评论后,我正在重新阅读您的问题,看来问题出在textLabel而不是detailTextLabel。因此,请编辑您的问题并澄清问题到底是什么。坦率地说,keypathdivelocation, divenumber在我看来非常可疑:你想在那里做什么?那是两个独立的字段吗?为什么不像divedate和divenumber那样处理它? -
不相关,但为什么表视图和索引路径变量是可选的?您可以省去解开非可选选项的麻烦。大声笑。
标签: ios tableview cell subtitle