How to add label text to DetailDisclosureButton?

依然范特西╮ 提交于 2019-12-10 12:49:06

问题


I'm working in a iOS Swift 2.0 application. I can't figure out for the life of me on how to set the text on the right side of a UITableViewCell just before the disclosure indicator chevron (besides creating a custom cell.accessoryView).

Here is a screenshot of the "Settings app" doing exactly what I'm trying to achieve.


回答1:


In Interface Builder, when setting up your cell, select the Right Detail style:

Then assign the value to the detailTextLabel property:

cell.detailTextLabel.text = "Kilroy Was Here"



回答2:


override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCell(withIdentifier: "CellId") ?? UITableViewCell(style: UITableViewCellStyle.value1, reuseIdentifier: "CellId")
    cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
    cell.textLabel?.text = "Main text"
    cell.detailTextLabel?.text = "Detail Text"

    return cell
}


来源:https://stackoverflow.com/questions/35400214/how-to-add-label-text-to-detaildisclosurebutton

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!