Unable to decline action sheet here

Added UILongPressGestureRecognizer with handleLongPressOnPhotos action to ImageView file. The most related codes are as follows:

- (IBAction)handleLongPressOnPhotos:(UILongPressGestureRecognizer *)sender
{
self.imageWillBeSaved = (UIImageView *)sender.view; //breakPoint1
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Save the photo" otherButtonTitles: @"Go to the Original photo", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showInView:self.view]; //breakPoint2
NSLog( @"actionSheet addr when created is %p", actionSheet );//breakPoint3
[actionSheet release];//breakPoint4
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    switch (buttonIndex) {
        case 0:
            UIImageWriteToSavedPhotosAlbum(self.imageWillBeSaved.image, self, @selector(image: didFinishSavingWithError:contextInfo:), nil);
            //[actionSheet dismissWithClickedButtonIndex:0 animated:YES]; i have tried to use this method here, but it didn't work.
            break;

        default:
            break;
    }
}

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    if (error != NULL)
    {
        // handle error
    }
    else 
    {
        // handle ok status
    }
}

The action sheet will not be rejected after clicking the "save photo" button. If I press the button again, the action sheet will be rejected and the photo will be saved twice. Any problem in the code? Thanks in advance!

Ps. imageView is the subtitle of scrollView, and scrollView is in the ViewCell table .

- (IBAction)handleLongPressOnPhotos:(UILongPressGestureRecognizer *)sender
{
self.imageWillBeSaved = (UIImageView *)sender.view; //breakPoint1
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Save the photo" otherButtonTitles: @"Go to the Original photo", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showInView:self.view]; //breakPoint2
NSLog( @"actionSheet addr when created is %p", actionSheet );//breakPoint3
[actionSheet release];//breakPoint4
}

handleLongPressOnPhotos: breakPoint1 breakPoint1. , imageView longPressed. : breakPoint1 → breakPoint2 → breakPoint1 → breakPoint2 → breakPoint3 → breakPoint4 → breakPoint3 → breakPoint4, . , ActionSheet , . , .

UILongPressGestureRecognizer

@Laddu, @MichaelDautermann, @sreecharan

0
3

UILongPressGestureRecognizer

@Laddu, @MichaelDautermann, @sreecharan

0

, , , nslog: -

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

  NSLog(@"buttonIndex.....%d",buttonIndex);

  switch (buttonIndex) {

     case 0:
        UIImageWriteToSavedPhotosAlbum(self.imageWillBeSaved.image, self, @selector(image: didFinishSavingWithError:contextInfo:), nil);

        //[actionSheet dismissWithClickedButtonIndex:0 animated:YES]; i have tried to use this method here, but it didn't work.

        break;

     default:
        break;
   }
}

, ACtionSheet .h.

+1

there is a reason you are not using actionSheet:willDismissWithButtonIndex:instead actionSheet:clickedButtonAtIndex:.

If you use actionSheet:willDismissWithButtonIndex:, you do not need to worry about firing the ActionSheet yourself.

0
source

All Articles