SMS*_*SMS 0 objective-c ios uicollectionview
您好,我想在编辑模式下禁用 uicollectionview 的第一个单元格。我在 cellforrow 中执行了以下代码
- (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;
}
Run Code Online (Sandbox Code Playgroud)
第一次在编辑模式下,我能够让用户单击所有单元格,但滚动后,第一行中的少数单元格会以随机方式禁用。任何人都可以建议我解决此问题的解决方案。
谢谢
当您 [cell setUserInteractionEnabled:NO];对单元格执行此操作时,将使用该单元格创建的单元格也会受到影响。因为它们位于您可以重复使用的队列中。因此,您需要在 item 0 控件的 else 中启用用户交互:
if (indexPath.item == 0){
...
} else {
[cell setUserInteractionEnabled:YES];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9120 次 |
| 最近记录: |