2

iOS 7 の uicollectionviewcell のサブビューと重なっているリロード時にアプリで UICollectionview を使用していますが、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 に答える