我在 UIViewController 中添加了一个表格视图。然后我在表格视图中的自定义单元格中添加了一个标签。我试图通过使用标签来更新 tableview 内的标签。似乎它不起作用。
这是我的代码。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("LineItemCell", forIndexPath: indexPath)
let object = lineItemsObject[indexPath.row]
//cell.textLabel?.text = object["quantity"]
print(object["description"]!)
if let descriptionLabel = cell.viewWithTag(500) as? UILabel {
descriptionLabel.text = object["description"]
}
else
{
print("fail")
}
return cell
}
当我总是调用该函数时,它不会读取标签并打印“失败”。我也为我的标签分配了正确的标签值。
请帮我解决问题。