问题
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