How to Set UITableViewCellStyleSubtitle and dequeueReusableCell in Swift?

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

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

My original Objective-C code was

13条回答
  •  旧时难觅i
    2020-12-01 05:39

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
    {
    
        var cell:UITableViewCell? =
            tableView.dequeueReusableCell(withIdentifier: "cell")
        if (cell != nil)
        {
            cell = UITableViewCell(style: UITableViewCellStyle.subtitle,
                                   reuseIdentifier: "cell")
        }
        cell!.textLabel?.text = "ABC"
        cell!.detailTextLabel?.text = "XYZ"
    
        return cell!
    
      }
    

提交回复
热议问题