swift detailTextLabel不显示 [英] swift detailTextLabel not showing up

查看:839
本文介绍了swift detailTextLabel不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ive检查了stackOverFlow一个解决方案,但它似乎仍然没有为我的代码工作..我的detailTextLabel仍然不显示:(



我做错了,这里是我的代码

  func tableView(tableView:UITableView,cellForRowAtIndexPath indexPath:NSIndexPath) - > UITableViewCell {
var cell = UITableViewCell()
//显示我们的排名数据
cell.textLabel?.text =\(championListInGame [indexPath.row])

if let url = NSURL(string:http://ddragon.leagueoflegends.com/cdn/img/champion/loading/\(championListInGame[indexPath.row])_0.jpg){
如果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细胞
}

我的胜利也没有失败出现在我的表格细胞,



在旁注中,有人可以教我如何选择宝宝蓝或宝宝红等颜色?对于我的应用程序,默认红色和蓝色太强:(



感谢帮助家伙!

解决方案

默认单元格样式没有 detailTextLabel 。您需要使用 .Value1 。 c> c: c:



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



< hr>

您可以使用 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)


Ive checked around stackOverFlow for a solution but it seemed like it still didnt work for my code.. my detailTextLabel still does not show up :(

Wondering what I am doing wrong, here's my code

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
}

my victory nor defeat showed up in my table cells however, the color, image, and text all showed up just as the way I wanted.

On the side note, can someone teach me how do I choose colors like baby blue or baby red ? the default red and blue is too strong for my app :(

Thanks for the help guys!

解决方案

The default cell style doesn't have a detailTextLabel. You need to use .Value1 or .Subtitle as the UITableViewCellStyle:

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


You can use the UIColor:red:green:blue:alpha: constructor to make custom colors. The values all vary from 0.0 to 1.0. You can look on the web for colors. If they are specified with values in the 0 to 255 range, you can convert them by dividing the values by 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)

这篇关于swift detailTextLabel不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆