2015-10-15 19 views
0

您好我想禁用uicollectionview的第一个单元格时编辑mode.I的确在cellforrow第一小区的UICollectionview用户交互禁用,禁用其他几个细胞也对滚动

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 


    MainCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath]; 

    cell.curveimageView.image = nil; 

    if(indexPath.item == 0){  
    [cell.curveimageView setImage:[UIImage imageNamed:@"AddCell"]]; 
    cell.subTitleText.text = @"New Cell"; 

     if(isEditing){ 
      [cell setUserInteractionEnabled:NO]; 
      [cell setAlpha:0.5]; 
     } 
     else{ 
      [cell setUserInteractionEnabled:YES]; 
      [cell setAlpha:1]; 
     } 
    } 
    else{ 

     [cell.curveimageView setImage:[UIImage imageNamed:@"FlowerImage"]]; 
     cell.subTitleText.text = [NSString stringWithFormat:@"%ld%@",(long)indexPath.row,@"Hello is this looking ok"]; 
    } 

    [cell setTag:indexPath.row]; 
    return cell; 
} 

下面的代码在第一次在编辑模式下,我可以让用户单击所有单元格,但在滚动后,第一行中的几个单元格会随机禁用。任何人都可以为我提供解决此问题的解决方案。

谢谢

回答

1

你的问题是:你的第一个单元格滚动后重新使用,并且您的代码不改变其状态,很快你可以用这个解决:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 


    MainCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath]; 

cell.curveimageView.image = nil; 

if(indexPath.item == 0){  
[cell.curveimageView setImage:[UIImage imageNamed:@"AddCell"]]; 
cell.subTitleText.text = @"New Cell"; 

    if(isEditing){ 
     [cell setUserInteractionEnabled:NO]; 
     [cell setAlpha:0.5]; 
    } 
    else{ 
     [cell setUserInteractionEnabled:YES]; 
     [cell setAlpha:1]; 
    } 
} 
else{ 

    [cell.curveimageView setImage:[UIImage imageNamed:@"FlowerImage"]]; 
    cell.subTitleText.text = [NSString stringWithFormat:@"%ld%@",(long)indexPath.row,@"Hello is this looking ok"]; 
// Add this: 
[cell setUserInteractionEnabled:YES]; 
     [cell setAlpha:1]; 
} 

[cell setTag:indexPath.row]; 
    return cell; 
} 
+0

Thanku,上面说的解决方案为我工作。 – SMS

2

当你做[cell setUserInteractionEnabled:NO];在一个单元格上,使用它创建的单元格也会受到影响。因为他们在可以重复使用的队列中。因此,您需要在项目0控制的其他项中启用用户交互:

if (indexPath.item == 0){ 
... 
} else { 
    [cell setUserInteractionEnabled:YES]; 
} 
1

问题在重复使用单元。设置setUserInteractionEnabled在其他情况下...

else{ 

// set user intraction enable . 
[cell setUserInteractionEnabled:YES]; 

[cell.curveimageView setImage:[UIImage imageNamed:@"FlowerImage"]]; 
cell.subTitleText.text = [NSString stringWithFormat:@"%ld%@",(long)indexPath.row,@"Hello is this looking ok"]; 

    [cell setAlpha:1]; 
} 

希望它能帮助你。

相关问题