在代码中初始化单元格时如何使用 detailTextLabel?
How to use detailTextLabel when initializing cell in code?
我在 IB 中没有原型单元格。我正在用代码初始化单元格。
let mycell = UITableViewCell(style: .Default, reuseIdentifier: "reuseIdentifier")
mycell.textLabel!.text = "main text"
mycell.detailTextLabel!.text = "test"
mycell.textLabel!.text
调用正常。但是 mycell.detailTextLabel!.text
调用使应用程序崩溃,因为 mycell.detailTextLabel
为零。我还需要做些什么才能使该部分正常工作吗?
我 运行 遇到了同样的问题 - 这很有帮助。
How to Set UITableViewCellStyleSubtitle and dequeueReusableCell in Swift?
使用类似于:
cell = UITableViewCell(style: UITableViewCellStyle.Subtitle,
reuseIdentifier: "identifier")
我在 IB 中没有原型单元格。我正在用代码初始化单元格。
let mycell = UITableViewCell(style: .Default, reuseIdentifier: "reuseIdentifier")
mycell.textLabel!.text = "main text"
mycell.detailTextLabel!.text = "test"
mycell.textLabel!.text
调用正常。但是 mycell.detailTextLabel!.text
调用使应用程序崩溃,因为 mycell.detailTextLabel
为零。我还需要做些什么才能使该部分正常工作吗?
我 运行 遇到了同样的问题 - 这很有帮助。
How to Set UITableViewCellStyleSubtitle and dequeueReusableCell in Swift?
使用类似于:
cell = UITableViewCell(style: UITableViewCellStyle.Subtitle,
reuseIdentifier: "identifier")