Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add label text to DetailDisclosureButton?

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.

cell accessory view screenshot

like image 999
ded Avatar asked Feb 15 '16 01:02

ded


2 Answers

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
}
like image 162
Dmitry Klochkov Avatar answered Nov 05 '22 00:11

Dmitry Klochkov


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

Right Detail

Then assign the value to the detailTextLabel property:

cell.detailTextLabel.text = "Kilroy Was Here"
like image 15
Dave Batton Avatar answered Nov 05 '22 01:11

Dave Batton