swift detailTextLabel不显示

编程入门 行业动态 更新时间:2024-10-28 11:27:54
本文介绍了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:ddragon.leagueoflegends/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)

您可以使用 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: "ddragon.leagueoflegends/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不显示

本文发布于:2023-11-26 20:25:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635070.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:swift   detailTextLabel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!