如何将标签文本添加到DetailDisclosureButton?

时间:2016-02-15 01:29:27

标签: ios swift uitableview accessoryview

我在iOS Swift 2.0应用程序中工作。我无法弄清楚如何在披露指标V形符号之前设置UITableViewCell右侧的文本(除了创建自定义cell.accessoryView之外)。

以下是“设置应用”的屏幕截图,正是我正在努力实现的目标。

cell accessory view screenshot

2 个答案:

答案 0 :(得分:9)

在Interface Builder中,设置单元格时,请选择右侧详细信息样式:

Right Detail

然后将值分配给detailTextLabel属性:

cell.detailTextLabel.text = "Kilroy Was Here"

答案 1 :(得分:6)

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
}