Unrecognized selector. Error while saving image using UIImageWriteToSavedPhotosAlbum

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

- (IBAction)handleLongPressOnPhotos:(UIImageView *)sender{
self.imageWillBeSaved = sender;
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]; 
[actionSheet release];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
switch (buttonIndex) {
    case 0:
        UIImageWriteToSavedPhotosAlbum(self.imageWillBeSaved.image, self, @selector(image: didFinishSavingWithError:contextInfo:), nil);

        break;

    default:
        break;
}

}

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

When you click the "save photo" button on the action bar, an error message appears: - [UILongPressGestureRecognizer image]: unrecognized selector sent to instance 0x21c2a0 Any problem in the code? Thanks in advance!

+3
source share
3 answers

Your sender is obviously UILongPressGestureRecognizer.

The methods that work when the gesture recognizer is activated should look like this:

- (void)nameOfMethodHere:(UIGestureRecognizer *)gestureRecognizer;

- , . , view. , .

+2

.

- (IBAction)handleLongPressOnPhotos:(UIImageView *)sender{
self.imageWillBeSaved = sender;

..

- (IBAction)handleLongPressOnPhotos:(UIGestureRecognizer *)sender{
self.imageWillBeSaved = sender.view;

... , , .

+5

UILongPressGestureRecognizer

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 1.0;
[YOURVIEW addGestureRecognizer:longPress];
[longPress release];    

UILongPressGestureRecognizer. , UIImageView UILongPressGestureRecognizer, .

- (void)handleLongPress:(UILongPressGestureRecognizer*)sender 
{ 
    if (sender.state == UIGestureRecognizerStateBegan) 
    {
         //YOUR CODE
    }
}
+2

All Articles