好吧,我是一个初学者,我创建了一个带有自定义单元格类的 UITableView,该单元格类按其应有的方式加载,并在每个文本标签中显示 2 个文本标签(cellPrice
和 cellTitle
)行/单元格(一切正常)。
但问题是当我调用删除行函数时,我无法访问文本标签的值。调用两个标签时出现相同的错误 - UITableViewCell 类型的值?没有成员cellPrice
'
我无法弄清楚为什么当单元格标签和值加载正常且正确时,但当我需要删除它们时我无法访问它们。请参阅下面我的代码。
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == UITableViewCellEditingStyle.Delete {
self.total - self.dict[tableView.cellForRowAtIndexPath(indexPath).cellPrice!.text!]
self.totalLabel.text = "Total: \(self.total)"
self.dict.removeValueForKey(tableView.cellForRowAtIndexPath(indexPath).cellTitle!.text!)
tableView.reloadData()
}
}
最佳答案
您必须将单元格转换为您的自定义类:
let cell = tableView.cellForRowAtIndexPath(indexPath) as! MyCustomCellClass
self.total - self.dict[cell.cellPrice!.text!]
关于swift - 删除单元格时无法访问 textLabel 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42073693/