Ios 从UICollectionView中删除项目

Ios 从UICollectionView中删除项目,ios,uicollectionview,uialertview,uiactionsheet,Ios,Uicollectionview,Uialertview,Uiactionsheet,我有一组图像显示在UICollectionView中。当用户点击一个图像时,它会生成一个UIActionSheet,其中包含该图像的一些选项。其中一个id从UICollectionView中删除照片。当用户在ui操作表中选择删除按钮时,会弹出一个警报视图,要求确认。如果用户选择“是”,则应删除照片 我的问题是,要从UICollectionView中删除该项,必须将indepath传递给deleteItemsAndExpaths事件。由于最终确认是在警报视图的didDismissWithButto

我有一组图像显示在
UICollectionView
中。当用户点击一个图像时,它会生成一个
UIActionSheet
,其中包含该图像的一些选项。其中一个id从
UICollectionView
中删除照片。当用户在
ui操作表
中选择删除按钮时,会弹出一个警报视图,要求确认。如果用户选择“是”,则应删除照片

我的问题是,要从
UICollectionView
中删除该项,必须将
indepath
传递给
deleteItemsAndExpaths
事件。由于最终确认是在警报视图的
didDismissWithButtonIndex
事件中授予的,因此我无法找到从那里获取所选图像的
indepath
以将其传递到
deleteItemsIndepath
事件的方法。我该怎么做

这是我的密码:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    switch (buttonIndex) {
        case 0:
            deletePhotoConfirmAlert = [[UIAlertView alloc] initWithTitle:@"Remove Photo"
                                                                 message:@"Do you want to remove this photo?"
                                                                delegate:self
                                                       cancelButtonTitle:@"Cancel"
                                                       otherButtonTitles:nil, nil];
            [deletePhotoConfirmAlert addButtonWithTitle:@"Yes"];
            [deletePhotoConfirmAlert show];

            break;
        case 1:
            NSLog(@"To Edit photo");
            break;
    }
}

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (alertView == deletePhotoConfirmAlert) {
        if (buttonIndex == 1) {
            // Permission to delete the button is granted here.
            // From here deleteItemsAtIndexPaths event should be called with the indexPath
        }
    }
}

- (void)deleteItemsAtIndexPaths:(NSArray *)indexPaths
{

}

为什么不使用[self.collectionView indexPathsForSelectedItems]。我这样做是为了一次删除多个图像

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
  if (alertView == deletePhotoConfirmAlert) {
    if (buttonIndex == 1) {
        // Permission to delete the button is granted here.
        NSArray *selectedItemsIndexPaths = [self.collectionView indexPathsForSelectedItems];

       // Delete the items from the data source.
        [self deleteItemsFromDataSourceAtIndexPaths:selectedItemsIndexPaths];

        // Now delete the items from the collection view.
        [self.collectionView deleteItemsAtIndexPaths:selectedItemsIndexPaths];
    }
  }
}

// This method is for deleting the selected images from the data source array
-(void)deleteItemsFromDataSourceAtIndexPaths:(NSArray  *)itemPaths {
   NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
   for (NSIndexPath *itemPath  in itemPaths) {
     [indexSet addIndex:itemPath.row];
   }
   [self.images removeObjectsAtIndexes:indexSet]; // self.images is my data source
}
编辑

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
   NSArray *indexpaths = [self.collectionView indexPathsForSelectedItems];
   DetailViewController *dest = [segue destinationViewController];
   dest.imageName = [self.images objectAtIndex:[[indexpaths objectAtIndex:0] row]];
}

我得到了一个不可见的@interface for'SomeViewController'在第行声明所选的'deleteItemsFromDataSourceAtIndexPaths'错误,
[self-deleteItemsFromDataSourceAtIndexPaths:selectedItemsIndexPaths].Sory我忘了指出deleteItemsFromDataSourceAtIndexPaths是我的自定义函数,用于从数据源数组中删除选定的图像。您可以直接在那里自己进行操作。在调用DeleteItemsAndExpaths之前,从数据源数组中删除图像非常重要:我明白了。现在,我尝试使用
removeObjectAtIndex
从数据源数组中删除图像。但是,由于它需要一个整数值,如何从
selectedItemsIndexPaths
数组中获取该值?工作非常完美。非常感谢,阿尼尔:)您好,有没有办法从
NSMutableIndexSet
中获取单个索引?