swift detailTextLabel 未显示

swift detailTextLabel not showing up

我已经在 Whosebug 周围检查了一个解决方案,但它似乎仍然不适用于我的代码。我的 detailTextLabel 仍然没有显示:(

想知道我做错了什么,这是我的代码

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell = UITableViewCell()
    // display our ranked data
    cell.textLabel?.text = "\(championListInGame[indexPath.row])"

    if let url = NSURL(string: "http://ddragon.leagueoflegends.com/cdn/img/champion/loading/\(championListInGame[indexPath.row])_0.jpg"){
        if let urlData = NSData(contentsOfURL: url){
            cell.imageView?.contentMode = UIViewContentMode.ScaleAspectFit
            cell.imageView?.image = UIImage(data: urlData)
        }
    }

    if victory[indexPath.row] == true {
        cell.backgroundColor = UIColor.blueColor()
        cell.detailTextLabel?.text = " "+"victory!"
    } else {
        cell.backgroundColor = UIColor.redColor()
        cell.detailTextLabel?.text = " "+"defeat!"
    }

    return cell
}

我的 table 单元格中显示了我的胜利或失败,但是,颜色、图像和文本都按照我想要的方式显示。

旁注,有人可以教我如何选择淡蓝色或淡红色等颜色吗?默认的红色和蓝色对我的应用来说太强了:(

感谢大家的帮助!

默认单元格样式没有 detailTextLabel。您需要使用 .Value1.Subtitle 作为 UITableViewCellStyle:

var cell = UITableViewCell(style: .Value1, reuseIdentifier: nil)

您可以使用 UIColor:red:green:blue:alpha: 构造函数来制作自定义颜色。这些值都在 0.0 到 1.0 之间变化。您可以在网上查找颜色。如果它们指定了 0 到 255 范围内的值,则可以通过将值除以 255.0 来转换它们:

let babyRed  = UIColor(red: 1.0, green: 0.6, blue: 0.6, alpha: 1.0)
let babyBlue = UIColor(red:128.0/255.0, green: 178.0/255.0, blue: 255.0/255.0, alpha: 1.0)