iphone - 如何使用 indexpath.row 从 UICollectionView 中删除项目

标签 iphone ios uicollectionview uicollectionviewcell

我有一个 Collection View ,我尝试使用 didSelect 方法从 Collection View 中删除一个单元格。我使用以下方法成功了

  [colleVIew deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];

但现在我需要从 CollectionView Cell 中删除单击按钮时的项目。这里我只得到 indexpath.row。 由此我无法删除该项目。 我试过这样。

-(void)remove:(int)i {

    NSLog(@"index path%d",i);
   [array removeObjectAtIndex:i];

   NSIndexPath *indexPath =[NSIndexPath indexPathForRow:i inSection:0];
   [colleVIew deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
    [colleVIew reloadData];
  }

但是需要重新加载CollectionView,所以删除后的cell排列动画是没有的。 请提出一个想法..提前致谢

最佳答案

-(void)remove:(int)i {

    [self.collectionObj performBatchUpdates:^{
        [array removeObjectAtIndex:i];
        NSIndexPath *indexPath =[NSIndexPath indexPathForRow:i inSection:0];
        [self.collectionObj deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];

    } completion:^(BOOL finished) {

    }];
}

试试这个。它可能对您有用。

关于iphone - 如何使用 indexpath.row 从 UICollectionView 中删除项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16296351/

相关文章:

ios - 以编程方式从 UIView 执行 Segue

ios - 出现键盘后UIWebView自动上移

ios - `applicationDidFinishLaunching` 在iOS项目中未调用

ios - 在从 UICollectionView 删除单元格之前的项目之后删除动画

ios - Swift3 iOS - 如何在按下单元格之前从 TableView 中的所有 IndexPath 获取数据

swift - 用用户选择的照片替换 Collection View 中的默认图像-swift

iphone - 由于 CIDetector 或 CIImage 导致 UIImage 倒置(转换问题)

ios - 即使检查相机是否可用,捕获图像崩溃源类型 1 也不可用

iOS 8 活力图像未在设备上显示

ios - 如何检测我是否正在访问仅限 iOS6 的方法?