【问题标题】:UIcollectionView Reload ovelaps in ios 7UIcollectionView在ios 7中重新加载重叠
【发布时间】:2013-10-29 06:29:43
【问题描述】:

当我重新加载时,我在我的应用程序中使用 UICollectionview,它与 ios 7 中 uicollectionviewcell 中的子视图重叠,但在 ios 6 中它工作正常,任何人都知道可能是什么原因以及如何解决这个问题。

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
    dispatch_async(dispatch_get_main_queue(), ^{
            if ([self.collectionviewFlow.indexPathsForVisibleItems containsObject:indexPath]) {
                NSString *img_name=[NSString stringWithFormat:@"%@_thumb%d.png",self.VaritiesName,(int)indexPath.row+1];
                imageVw=[[UIImageView alloc]initWithImage:[UIImage imageNamed: img_name]];
                imageVw.frame=CGRectMake(10,10,100,100);
                [cell.contentView addSubview:imageVw];
            }
        });
    cell.backgroundColor=[UIColor clearColor];
    return cell;
}

【问题讨论】:

  • 发布你的一些代码。
  • 我已附上代码

标签: ios iphone ios7 uicollectionview


【解决方案1】:

试试这个方法... 告诉我

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
    dispatch_async(dispatch_get_main_queue(), ^{

      //  ********* Changed *******

       for (UIView *v in [cell.contentView subviews])
        [v removeFromSuperview];

     // ********** Changed **********
            if ([self.collectionviewFlow.indexPathsForVisibleItems containsObject:indexPath]) {
                NSString *img_name=[NSString stringWithFormat:@"%@_thumb%d.png",self.VaritiesName,(int)indexPath.row+1];
                imageVw=[[UIImageView alloc]initWithImage:[UIImage imageNamed: img_name]];
                imageVw.frame=CGRectMake(10,10,100,100);
                [cell.contentView addSubview:imageVw];
            }
        });
    cell.backgroundColor=[UIColor clearColor];
    return cell;
}

【讨论】:

  • 这对您有帮助吗?
  • 我还有一个疑问,我在重新加载时使用此代码会占用大量内存并“收到内存警告”。并使应用程序崩溃。请帮助我...
  • 如果图像很大,请尝试减小图像大小或在文件/项目中使用 ARC。
  • 我已经加载了六张 3 行的图片,每行两张图片的大小为 140*140,并且我只有启用 ARC 的项目..那么它还会使图片大小的任何想法崩溃吗?
  • 使用 Instrument 工具并检查它需要更多内存的地方。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多