Issue with UITableViewCells Repeating Content

我是研究僧i 提交于 2021-01-29 11:00:52

问题


My app shows the user local bus departures however when Night Buses start to show the red 'N' shows in other services after scrolling as shown in the screenshots below, additionally the route numbers start to be wrong. The route numbers are correct the rest of the time when scrolling, it is only when the Night Buses appear

This is the code I have executed for setting the route number

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()!)

回答1:


The solution was as suggested by Mohamed Mostafa in the comments was to reset the value of the UIButton and set the value again using

cell.route.setAttributedTitle(NSMutableAttributedString(string: "\(departureRoutes[indexPath.row + 1])"), for: .normal)

Then performing the switch code after this



来源:https://stackoverflow.com/questions/51679033/issue-with-uitableviewcells-repeating-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!