投稿のUITableView
があります。
投稿のIDがsqliteに保存されています
オレンジ色の記事や黒色の記事を見せたいと思います。
しかし、私はwillDisplayCell
メソッドで見たポストのためにオレンジ色を設定すると、いくつかのセルがオレンジ色に間違って色付けされます。そうでなければ、印刷ログ( "Color it")は正しいです。UITableView willDisplayCellメソッドの不具合
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()
}
}
たとえば、1つの投稿だけが表示されている場合、「カラー」が1回印刷されます。それは正しい。しかし、他のいくつかのセルは、 "Color it"ログなしでオレンジ色に着色されています。
CellForRowAtIndexPathを使用してセルのスタイルを設定しない理由は何ですか? –
カスタムセルを使用する – Developer
@SandeepBhandari DataSourceでCellForRowAtIndexPathを使用しましたが、データソースでスタイルを設定したくありません –