gpt4 book ai didi

ios - 快速滚动时自定义 UITableViewCell 更改字体

转载 作者:行者123 更新时间:2023-11-28 13:17:56 25 4
gpt4 key购买 nike

我有一个自定义的 UITableViewCell,其中有一个 UILabel

这是我的代码:

 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

var cell = tableView.dequeueReusableCellWithIdentifier(
"PromoCell", forIndexPath: indexPath) as? SchedaCompletaCellTVC // it's my custom tableview cell

if (cell == nil) {
cell = SchedaCompletaCellTVC(style: UITableViewCellStyle.Default,reuseIdentifier:"PromoCell")
}

// Configure the cell...
switch indexPath.row {
case 0:
cell!.valueLabel.text = String(htmlEncodedString: company.name)
cell!.valueLabel.font = UIFont(name: "Helvetica-Bold", size: 17.0)

case 1:
cell!.valueLabel.text = String(htmlEncodedString: company.description)
case 2:
cell!.valueLabel.text = "Contatti"
cell!.valueLabel.font = UIFont(name: "Helvetica-Bold", size: 15.0)
case 3:
cell!.valueLabel.text = "Indirizzo: \(String(htmlEncodedString: company.address)),\(String(htmlEncodedString: company.city)),\(String(htmlEncodedString: company.province)) "
case 4:
var telString:NSString = String(htmlEncodedString: company.phone)
cell!.valueLabel.text = "Tel: \(telString)"

case 5:
var email = String(htmlEncodedString: company.email)
cell!.valueLabel.text = "Email: \(email)"

case 6:
var sitoweb = String(htmlEncodedString: company.site)
cell!.valueLabel.text = "Sito: \(sitoweb)"

case 7:
cell!.valueLabel.text = "Fax: \(String(htmlEncodedString: company.fax))"
default:
cell!.valueLabel.text = ""

}


return cell!
}

当我向下滚动时,单元格会显示错误的字体并且每次都会更改。

希望大家帮帮忙!谢谢。

最佳答案

看这里:

var cell = tableView.dequeueReusableCellWithIdentifier(
"PromoCell", forIndexPath: indexPath) as? SchedaCompletaCellTVC // it's my custom tableview cell

if (cell == nil) {
cell = SchedaCompletaCellTVC(style: UITableViewCellStyle.Default,reuseIdentifier:"PromoCell")
}

您正在重复使用该单元格。在某些单元格中,您正在设置字体,而在其他一些单元格中,您没有对字体属性进行任何更改。

switch indexPath.row {
case 0:
cell!.valueLabel.text = String(htmlEncodedString: company.name)
cell!.valueLabel.font = UIFont(name: "Helvetica-Bold", size: 17.0)

case 1:
cell!.valueLabel.text = String(htmlEncodedString: company.description)
case 2:
cell!.valueLabel.text = "Contatti"
cell!.valueLabel.font = UIFont(name: "Helvetica-Bold", size: 15.0)
case 3:
cell!.valueLabel.text = "Indirizzo: \(String(htmlEncodedString: company.address)),\(String(htmlEncodedString: company.city)),\(String(htmlEncodedString: company.province)) "
case 4:
var telString:NSString = String(htmlEncodedString: company.phone)
cell!.valueLabel.text = "Tel: \(telString)"

case 5:
var email = String(htmlEncodedString: company.email)
cell!.valueLabel.text = "Email: \(email)"

case 6:
var sitoweb = String(htmlEncodedString: company.site)
cell!.valueLabel.text = "Sito: \(sitoweb)"

case 7:
cell!.valueLabel.text = "Fax: \(String(htmlEncodedString: company.fax))"
default:
cell!.valueLabel.text = ""
}

在 3、4、5、6、7 中你没有设置字体。在将起作用的那些单元格中设置所需的字体大小。 :)

关于ios - 快速滚动时自定义 UITableViewCell 更改字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28187775/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com