2015-10-15 20 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]; 
} 

希望它能幫助你。

相關問題