UITableViewCell not showing detailTextLabel.text - Swift

前端 未结 11 2246
慢半拍i
慢半拍i 2020-12-14 06:45

The detail (subtitle) text does not appear. The data are available, though, because when a println() call is added, it prints Optional(\"data\") to the console with the expe

11条回答
  •  囚心锁ツ
    2020-12-14 07:31

    Same issue here (from what I've read, perhaps a bug in iOS 8?), this is how we worked around it:

    1. Delete the prototype cell from your storyboard

    2. Remove this line:

    var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell

    1. Replace with these lines of code:
    let cellIdentifier = "Cell"
    
    var cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? UITableViewCell
    if cell == nil {
        cell = UITableViewCell(style: UITableViewCellStyle.Value2, reuseIdentifier: cellIdentifier)
    }
    

    Update for Swift 3.1

    let cellIdentifier = "Cell"
    
    var cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier)
    if cell == nil {
        cell = UITableViewCell(style: UITableViewCellStyle.value2, reuseIdentifier: cellIdentifier)
    }
    

    Update for Swift 4.2 - Simplified

    let cell = UITableViewCell(style: UITableViewCell.CellStyle.value2, reuseIdentifier: "cellId")
    

提交回复
热议问题