我的应用程序显示了用户的本地巴士发车时间,但是,如下面的屏幕截图所示,当滚动后夜间巴士在其他服务中开始显示红色的'N'时,此外,路线号也开始错误。滚动时的其余时间,路线编号是正确的,只有当出现夜间巴士时
这是我为设置路线号而执行的代码
case "N3", "N7", "N11","N16","N22","N25","N26","N30","N31","N34", "N37","N44","N98", "N106","N113","N124":
var route = NSMutableAttributedString()
route = NSMutableAttributedString(string: departureRoutes[0].rawString()!)
route.addAttribute(NSAttributedStringKey.foregroundColor, value: UIColor.red, range: NSRange(location:0,length:1))
route.addAttribute(NSAttributedStringKey.foregroundColor, value: UIColor.white, range: NSRange(location:1,length:(departureRoutes[0].string?.count)! - 1))
cell.route.setAttributedTitle(route, for: .normal)
default :
cell.route.tintColor = routeColor(routeno: departureRoutes[0].rawString()!)
答案 0 :(得分:0)
Mohamed Mostafa在评论中建议的解决方案是重置UIButton的值并使用再次设置该值
cell.route.setAttributedTitle(NSMutableAttributedString(string: "\(departureRoutes[indexPath.row + 1])"), for: .normal)
然后在此之后执行切换代码