セルが開かれているかどうかを確認するtableViewがあります。はいの場合は空のセル(画像なし)が表示され、いいえの場合はセルがまだ読み取られていない(開かれていない)ことを示す小さな画像が表示されます。
これで、アプリに「お気に入り」機能があり、tableViewにセルがお気に入りであることを示す小さな画像を表示して、ユーザーがテーブルからお気に入りに追加されたものをすばやく認識できるようにします。
cellForRowAtIndexPath
私は方法でやろうとしていました
NSDictionary *item = [rows objectAtIndex:indexPath.row];
cell.textLabel.text = [item objectForKey:@"name"];
if ([[item valueForKey:@"isRead"] boolValue] == NO) {
cell.imageView.image = [UIImage imageNamed:@"unread.png"];
} else {
if ([[item valueForKey:@"isFav"] boolValue] == YES){
cell.imageView.image = [UIImage imageNamed:@"favorite.png"];
}
else{
cell.imageView.image = nil;
}
cell.imageView.image = nil;
}
ここname
でisRead
、、isFav
は、すべてのデータを格納するplistから取得した値です。もちろん、ユーザーがセルを開くと、「未読」の画像は消えます。
問題は、未読とお気に入りの両方を表示したいということです。上記のコードでは、未読のものだけが表示されます。
これを達成するにはどうすればよいですか?多分愚かな何かが欠けています!