【问题标题】:How to add label text to DetailDisclosureButton?如何将标签文本添加到 DetailDisclosureButton?
【发布时间】:2016-05-25 19:44:59
【问题描述】:

我正在使用 iOS Swift 2.0 应用程序。我终其一生都想不出如何在 UITableViewCell 右侧设置文本,就在披露指示符 V 形之前(除了创建自定义 cell.accessoryView)。

这是“设置应用”的屏幕截图,正是我想要实现的功能。

【问题讨论】:

  • 您可以使用自定义单元格来实现它。

标签: ios swift uitableview accessoryview


【解决方案1】:

在 Interface Builder 中,设置单元格时,选择 Right Detail 样式:

然后将值赋给detailTextLabel属性:

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
    }
    

    【讨论】:

      猜你喜欢
      • 2021-07-11
      • 2019-07-16
      • 1970-01-01
      • 2019-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多