Nat*_*an 2 xcode uitableview subtitle swift
我目前正在Swift中开发一个将数据存储到表中的应用程序.目前我在主要文本下遇到字幕文本问题.我想在"许可证号码"下添加几行字幕,请参考图像.我已准备就绪,但不确定如何让它可见.任何帮助,将不胜感激
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Value2, reuseIdentifier: "Nil")
cell.textLabel!.text = LrnLog.logs[indexPath.row].name //Trip Date- The data is used for the name
cell.detailTextLabel!.text = LrnLog.logs[indexPath.row].desc //Trip Name
cell.detailTextLabel!.text = LrnLog.logs[indexPath.row].rego //Vehicle Rego
cell.detailTextLabel!.text = LrnLog.logs[indexPath.row].licnum //License Number
return cell
}
Run Code Online (Sandbox Code Playgroud)
您应该text在一个控制流程中(或在一个代码块内)分配一次,您不能一个接一个地将不同的文本重新分配给同一个属性.如果你这样做,那么编译器将考虑最新的而不是全部.所以要回答你的问题,试试这个cellForRowAtIndexPath:
cell.detailTextLabel!.numberOfLines = 0
cell.textLabel!.text = LrnLog.logs[indexPath.row].name
cell.detailTextLabel!.text = "\(LrnLog.logs[indexPath.row].desc)\n\(LrnLog.logs[indexPath.row].rego)\n\(LrnLog.logs[indexPath.row].licnum)"
Run Code Online (Sandbox Code Playgroud)
假设没有在上面的属性LrnLog.logs[indexPath.row]都nil否则它会崩溃.所以最好检查nil然后分配值.当字幕行变高时,您还需要调整单元格的大小.
| 归档时间: |
|
| 查看次数: |
1188 次 |
| 最近记录: |