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

标签 iphone ios uigesturerecognizer uiactionsheet 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
}
}

当单击操作表上的“保存照片”按钮时,错误消息为:-[UILongPressGestureRecognizer image]: unrecognized selector sent to instance 0x21c2a0 代码有问题吗?提前致谢!

最佳答案

只需替换前两行..

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

与..

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

这应该有效……David 很好地解释了发生这种情况的原因。

关于iphone - 使用 UIImageWriteToSavedPhotosAlbum 保存图像时无法识别的选择器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10510506/

相关文章:

iphone相当于android打开其他应用程序的意图

javascript - 区分移动键盘上的keyup

ios - Float、Double、Int 是 AnyObject 吗?

ios - 澄清 Objective-C 协议(protocol)和授权

ios - 为 iCloud "Manage Storage"列表指定应用名称

ios - 为什么不执行 segue

android - 使用 Web App 的移动推送通知

iphone - 使用 SDURLCache(NSURLCache 的子类)时的内存泄漏

iphone - UIView 覆盖另一个 uiview 并传递触摸

iphone - 为什么这是一个无限循环?