UITableViewCell not showing detailTextLabel.text - Swift

前端 未结 11 2372
慢半拍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条回答
  •  Happy的楠姐
    2020-12-14 07:29

    In Xcode11 and Swift5 , We have to do like below. If we do it by checking the condition cell == nil and then creating UITableViewCell with cellStyle it is not working . Below solution is working for me .

        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
               let cellIdentifier = "Cell"
                let cell = UITableViewCell(style: UITableViewCell.CellStyle.subtitle, reuseIdentifier: cellIdentifier)
        cell?.textLabel?.text = "Title"
        cell?.detailTextLabel?.text = "Sub-Title"
    
       return cell!
        }
    

提交回复
热议问题