How to Set UITableViewCellStyleSubtitle and dequeueReusableCell in Swift?

前端 未结 13 998
攒了一身酷
攒了一身酷 2020-12-01 05:03

I\'d like a UITableView with subtitle-style cells that use dequeueReusableCellWithIdentifier.

My original Objective-C code was

13条回答
  •  一生所求
    2020-12-01 05:46

    Just building upon memmons' answer by cleaning it up Swift 2 style...

    let cell = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier) ?? UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: reuseIdentifier)
    
    cell.detailTextLabel?.text = "some text"
    
    return cell
    

    Swift 3:

    let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier) ?? UITableViewCell(style: .subtitle, reuseIdentifier: cellIdentifier)
    
    cell.detailTextLabel?.text = ""
    
    return cell
    

提交回复
热议问题