我的问题是,要从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中删除项目所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)