Reputation: 21520
I'm working with UICollectionViewCell to display a list of events.
How can I mark (forever) each cell as "read" when it compare on screen?
I can do this if I scroll down only, if I "play" with scroll (moving up and down), stop working marking as read "random" cell: I think is caused by reuse of cell. So, how can I solve this?
Details:
Each cell is a customized Nib
NSString* cellName = [[MyCell class] description];
UINib* nib = [UINib nibWithNibName:cellName bundle:[NSBundle mainBundle]];
[self.collectionView registerNib:nib forCellWithReuseIdentifier:name];
And in cellForItemAtIndexPath delegate:
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
NSString* name = [[MyCell class] description];
QVEventWallPostCell *cell = [cv dequeueReusableCellWithReuseIdentifier:name forIndexPath:indexPath];
if(/* control */) {
[cell markAsRead];
} else {
/* */
}
...
}
Upvotes: 0
Views: 134
Reputation: 337
Add isRead boolean property to the Event object you use to display data in each cell instead of the cell itself, and check on its value the next time you display the cell
Event* thisEvent= [self.dataSource objectAtIndex:indexPath.item];
if(!thisEvent.isRead) {
thisEvent.isRead=YES;
// whatever function you use to show the cell as unread; in case the cell is reused from a read cell
}
else {
// whatever function you use to show the cell as read
}
Upvotes: 2