请帮我,如何保存UICollectionViewCell
的状态。例如:我有带有UIWebView
的单元格,当我使用dequeueReusableCellWithReuseIdentifier:forIndexPath:
返回错误的单元格时,不是为这个indexPath
,然后UIWebView
的内容将重新加载以获得正确的indexPath
,并且会出现抽搐。谢谢!
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
NewsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NEWS_CELL" forIndexPath:indexPath];
if (!cell.isShowed) { // I just added boolean property
cell.isShowed = YES;
/*** some init actions ***/
}
return cell;
}
如果我使用这种方法,那些 cell.isShowed == YES
的单元格会返回错误的 indexPath
。但是如果我不使用 cell.isShowed
,每次显示时 UIWebView 的内容都将重新加载。