【问题标题】:How to save state of UICollectionViewCell如何保存 UICollectionViewCell 的状态
【发布时间】:2012-11-17 14:14:03
【问题描述】:

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

【问题讨论】:

  • 你使用了正确的 indexPath 吗?
  • 是的,我只使用 indexPath 从 - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  • “不适合这个 indexPath”是什么意思?你能粘贴你的代码吗?我需要更多代码来看看你有什么问题。
  • "return on wrong indexPath" 表示单元格显示成功但行错了?
  • 那么,sunkehappy,您对此有什么想法吗? :)

标签: objective-c ios uiwebview uicollectionview uicollectionviewcell


【解决方案1】:

看看 Apple 的 UIWebView Class Reference 怎么说:

重要提示:您不应将 UIWebView 或 UITableView 对象嵌入 UIScrollView 对象。如果这样做,可能会导致意外行为 因为两个对象的触摸事件可能会混淆和错误 处理。

但是UICollectionView 继承自UIScrollView。所以你需要重新设计你的架构。

【讨论】:

  • webView.scrollView.scrollEnabled = NO; ?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-14
  • 1970-01-01
  • 1970-01-01
  • 2014-06-07
  • 2022-01-08
相关资源
最近更新 更多