2014-09-22 83 views
2

我试图添加许多细节(字段)以在TableView中显示。通过CONCAT各个领域,并把在detailTextLabel如:如何在TableView中添加2个以上的detailTextLabel(Swift)

来源:

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 
} 

谁能指出任何其他方式获得更好的代码,许多领域在视图中显示。

+2

您可以使用自定义单元格。 – 2014-09-22 05:27:31

+1

我搜索了“自定义单元格”找到了相关的代码和导师。 Thks – 2014-09-22 06:34:19

+0

欢迎@ user3528013 – 2014-09-22 06:55:26

回答

0

我认为你的第一种方法很好。在原型单元格中的故事板中,您可以放置​​多个UILabels。然后像你一样更新每个标签。您可以将标签放置在xib中或使用代码创建它们。但是,拥有多个标签然后单独更新它们没有任何问题。这可以提供更大的连接灵活性,因为您可以根据需要使每个标签中的文本合理化,从而使tableview更加美观。所以每个单元格行都与上面的单元行保持一致。

+0

我来自PHP和当然新的Swift/Xcode。当从数据库到数组重新输入数据时,做这样的每一个都很困难。我无法赋予数组
[cell.textLabel?.text = tasksList [indexPath.row] .name var yString = tasksList [indexPath.row] .desc var xString = tasksList [indexPath.row] .amnt] 错误'任何对象'都没有成员名称desc – 2014-09-22 09:09:50

相关问题