ios – 从UICollectionView中删除项目

ios – 从UICollectionView中删除项目,第1张

概述我有一组显示在UICollectionView中的图像.当用户点击图像时,它会生成一个UIActionSheet,其中包含该图像的几个选项.其中一个从UICollectionView中删除照片.当用户在UIActionSheet中选择删除按钮时,它会d出一个警报视图,要求确认.如果用户选择是,则应删除照片. 我的问题是,要从UICollectionView中删除该项,您必须将indexPath传递 我有一组显示在UICollectionVIEw中的图像.当用户点击图像时,它会生成一个UIActionSheet,其中包含该图像的几个选项.其中一个从UICollectionVIEw中删除照片.当用户在UIActionSheet中选择删除按钮时,它会d出一个警报视图,要求确认.如果用户选择是,则应删除照片.

我的问题是,要从UICollectionVIEw中删除该项,您必须将indexPath传递给deleteItemsAtIndexPaths事件.由于在警报视图的dIDdismissWithbuttonIndex事件中授予了最终确认,因此我无法找到从该处获取所选图像的indexPath以将其传递给deleteItemsAtIndexPaths事件的方法.我怎样才能做到这一点?

这是我的代码:

- (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]];}
总结

以上是内存溢出为你收集整理的ios – 从UICollectionView中删除项目全部内容,希望文章能够帮你解决ios – 从UICollectionView中删除项目所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1078538.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存