使用UIImageWriteToSavedPhotosAlbum保存图像时无法识别的选择器错误

lu *_*uan 3 iphone uiactionsheet uigesturerecognizer ios unrecognized-selector

一个UILongPressGestureRecognizer添加到我的ImageView用行动handleLongPressOnPhotos.最相关的代码如下:

- (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
}
}
Run Code Online (Sandbox Code Playgroud)

单击操作表上的"保存照片"按钮时,会显示一条错误消息:- [UILongPressGestureRecognizer image]:无法识别的选择器发送到实例0x21c2a0 代码中有任何问题吗?提前致谢!

Ank*_*ava 5

只需更换前两行..

- (IBAction)handleLongPressOnPhotos:(UIImageView *)sender{
self.imageWillBeSaved = sender;
Run Code Online (Sandbox Code Playgroud)

与..

- (IBAction)handleLongPressOnPhotos:(UIGestureRecognizer *)sender{
self.imageWillBeSaved = sender.view;
Run Code Online (Sandbox Code Playgroud)

这应该有效......大卫很好地解释了这种情况发生的原因.