You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何编辑Table View原型单元格的Style?Right Detail右侧字段怎么访问?

Swift 中 Table View 原型单元格相关问题解答

1. 如何编辑Table View原型单元格的Style部分?

在Xcode里按以下步骤操作:

  • 打开对应故事板,找到目标Table View
  • 选中其中的原型单元格
  • 打开右侧的属性检查器(快捷键:Option + Command + 4)
  • 在Style下拉菜单里选择需要的样式,比如"Right Detail"

2. 如何访问Right Detail样式下的右侧Detail文本字段?

在tableView(_:cellForRowAt:)方法中,通过cell.detailTextLabel?.text即可访问并设置右侧文本,示例代码如下:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "你的单元格标识", for: indexPath)
    // 设置左侧主文本
    cell.textLabel?.text = "左侧内容"
    // 设置右侧详情文本
    cell.detailTextLabel?.text = "右侧详情"
    return cell
}

内容的提问来源于stack exchange,提问作者Lionel Yu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 22:30:53