gpt4 book ai didi

objective-c - 如何保存 UICollectionViewCell 的状态

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:43:56 26 4
gpt4 key购买 nike

请帮助我,如何保存 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 的内容将在每个显示单元格中重新加载对不起我的英语:)

最佳答案

看看苹果的UIWebView Class Reference说:

Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.

但是UICollectionView继承自UIScrollView。因此,您需要重新设计架构。

关于objective-c - 如何保存 UICollectionViewCell 的状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13431375/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com