自定義單元類具有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