I have a set of images showing in a UICollectionView
. When the user taps on an image, it spawns a UIActionSheet
with a few options for that image. One of them id removing the photo from the UICollectionView
. When the user selects remove button in the UIActionSheet
, it pops up an alert view asking for confirmation. If the user selects yes, it should remove the photo.
My problem is, to remove the item from the UICollectionView
, you have to pass the indexPath
to the deleteItemsAtIndexPaths
event. Since the final confirmation is granted in the alert view's didDismissWithButtonIndex
event, I can't figure out a way to get the indexPath
of the selected image from there to pass it to deleteItemsAtIndexPaths
event. How can I do this?
Here's my code:
- (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
{
}