我有一组图像显示在UICollectionView
. 当用户点击图像时,它会生成UIActionSheet
带有该图像的一些选项的 a。其中一个 ID 从UICollectionView
. 当用户在 中选择删除按钮时UIActionSheet
,它会弹出一个警报视图,要求确认。如果用户选择是,它应该删除照片。
我的问题是,要从 中删除项目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
{
}