【问题标题】:How to add more than 2 detailTextLabel in TableView (Swift)如何在 TableView (Swift) 中添加超过 2 个 detailTextLabel
【发布时间】:2014-09-22 04:12:56
【问题描述】:

我尝试添加许多详细信息(字段)以在 TableView 中显示。通过连接每个字段并放入 detailTextLabel 例如:

发件人:

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!{

    let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier:"test")

    cell.textLabel.text = taskMgr.tasks[indexPath.row].name
    cell.detailTextLabel.text = taskMgr.tasks[indexPath.row].desc

    return cell
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
    let cell:UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "Test")
    cell.textLabel?.text=tasksList[indexPath.row].name
    var yString = tasksList[indexPath.row].desc
    var xString = tasksList[indexPath.row].amnt

    var zString = xString+" "+yString
    cell.detailTextLabel?.text=zString
    return cell
}

任何人都可以指出任何其他方法,以便更好地在视图中显示许多字段的代码。

【问题讨论】:

  • 您可以使用自定义单元格。
  • 我搜索“自定义单元格”找到了相关代码和导师。谢谢
  • 欢迎@user3528013

标签: uiview swift


【解决方案1】:

我认为您的第一种方法很棒。在原型单元内的情节提要中,您可以放置​​多个 UILabel。然后像你一样更新每个标签。您可以将标签放置在 xib 中或在代码中创建它们。但是拥有多个标签然后单独更新它们并没有错。这为连接提供了更大的灵活性,因为您可以根据需要证明每个标签中的文本以使 tableview 漂亮。所以每个单元格行都与它上面的行对齐。

【讨论】:

  • 我来自 PHP,当然也是 Swift/Xcode 的新手。在从数据库到数组中检索数据时,每一个都很难做到。我无法分配给数组
    [cell.textLabel?.text=tasksList[indexPath.row].name var yString = tasksList[indexPath.row].desc var xString = tasksList[indexPath.row].amnt]错误“任何对象”没有成员名称 desc
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-14
  • 2018-06-05
  • 2023-04-02
  • 2023-01-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多