如何在副标题中显示数字?

时间:2016-12-09 21:21:54

标签: swift

我刚学会了如何使用swift,并想知道如何转换detailTextLabel,以便它会显示为字幕中的数字?现在,唯一显示的是Pname,副标题是空的。这是我的代码:

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("pCell", forIndexPath: indexPath)

    cell.textLabel?.text = products[indexPath.row].valueForKey("PName") as? String
    cell.detailTextLabel?.text = products[indexPath.row].valueForKey("Price") as? String

    return cell

我的另一个问题是,有没有办法在这个func tableview中编写代码来计算价格并让它显示在detailTextLabel中?或者我必须通过NSObject传递它?

1 个答案:

答案 0 :(得分:0)

假设products[indexPath.row].valueForKey("Price") as! Int,您可以执行cell.detailTextLabel?.text = String(products[indexPath.row].valueForKey("Price") as! Int)