2

当我重新加载时,我在我的应用程序中使用 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;
}
4

1 回答 1

2

试试这种方式... &让我知道

- (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;
}
于 2013-10-29T07:04:33.173 回答