In UITableView, cell.detailTextLabel.text isn't working… why?

前端 未结 9 1041
逝去的感伤
逝去的感伤 2020-12-08 00:34

In tableView:cellForRowAtIndexPath: I have the following:

cell.textLabel.text = @\"label\";
cell.detailTextLabel.text = @\"detail\";
         


        
9条回答
  •  轮回少年
    2020-12-08 00:48

    Swift 3:

    If you're making your cell with overriding the "cellForRowAt indexPath" function:

    let tableContent = ["1", "2", "3", "4", "5"]
    let tableDetailContent = ["a", "b", "c", "d", ""]
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = UITableViewCell(style: UITableViewCellStyle.subtitle, reuseIdentifier: "yourCellIdentifier")
        cell.textLabel?.text = tableContent[indexPath.row]
        cell.detailTextLabel?.text = tableDetailContent[indexPath.row]
    
        return cell
    }
    

    This code part from above allows you to set your detailTextLabel.. You can set whatever you want on storyboard for Table View Cell style (Custom, Basic, Right Detail, Left Detail, Subtitle), this line will override it:

    style: UITableViewCellStyle.subtitle
    

提交回复
热议问题