自定义单元类具有override func layoutSubviews(),其中每个单元格的detailTextLabel都被赋予标题“Jim”。单击DidSelectRowAtIndexPath后,是否有方法永久更改单元格的细节文本(以阻止单元格不断细化Jim),让我们说“Bob”?如何修改DidSelectRowAtIndexPath中的自定义单元格
//This function is in the custom cell UserCell
class CustomCell: UITableViewCell {
override func layoutSubviews() {
super.layoutSubviews()
detailTextLabel?.text = "Jim"
}
///........
}
//In the viewController with the tableView outlet
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
//.....
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(cellId, forIndexPath: indexPath) as! CustomCell
//......
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
/* Code I need to convert the detailTextLabel.text to equal "Bob" upon clicking on certain cell */
}
谢谢你的回答,尽管我已经尝试过了,它仍然是Jim,重写func layoutSubviews在tableView重新载入时被调用,因此在我将它声明为我的didSelectRow中的Bob后将它放回到Jim。 ... – slimboy