有一个 UITableView
的帖子。
已查看的帖子 ID 保存在 sqlite 中
我想显示,看到的帖子是橙色的,其他的是黑色的。
但是当我在 willDisplayCell
方法中为 seen post 设置橙色时,一些单元格被错误地着色为橙色,否则打印日志(“Color it”)是正确的。
override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
let post = postDataSource.posts[indexPath.row]
print(post.id)
let cellPost = cell as? PostListViewCell
if post.isRead.boolValue == true {
print("Color it")
cellPost!.body.textColor = UIColor.orangeColor()
cellPost!.title.textColor = UIColor.orangeColor()
}
}
例如,如果只看到一篇文章,则打印一次“Color it”。这是正确的。但是其他一些单元格是橙色的,没有“Color it”日志。
最佳答案
尝试完成 if 语句
if (post.isRead.boolValue == true) {
print("Color it")
cellPost!.body.textColor = UIColor.orangeColor()
cellPost!.title.textColor = UIColor.orangeColor()
}else{
cellPost!.body.textColor = UIColor.blackColor()
cellPost!.title.textColor = UIColor.blackColor()}
关于ios - UITableView willDisplayCell 方法的不当行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44519945/