无法在此处关闭操作表 [英] Can not dismiss an action sheet here

查看:65
本文介绍了无法在此处关闭操作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个UILongPressGestureRecognizer通过操作handleLongPressOnPhotos添加到了我的imageView中.最相关的代码如下:

A UILongPressGestureRecognizer is added to my imageView with action handleLongPressOnPhotos. The most related codes is as following:

- (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 dismissed after i click the "save the photo" button. If i click the button again, the action sheet dismissed and the photo saved twice.Any problem in the code? Thanks in advance!

Ps. imageView是scrollView的子视图,并且scrollView在tableViewCell中.

- (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之后,我遵循了代码的步骤.步骤顺序为:中断点1->中断点2->中断点1->中断点2->中断点3->中断点4->中断点3->中断点4,然后熄灭.显而易见,actionSheet已被显示两次,从而导致了问题.很奇怪,我不知道原因,避免这种情况.

I set two breakpoint in the "handleLongPressOnPhotos:" method as breakPoint1 and breakPoint1. I followed the steps of the code after the imageView was longPressed. The step order is :breakPoint1 -> breakPoint2 ->breakPoint1 ->breakPoint2 - > breakPoint3 -> breakPoint4 - > breakPoint3 -> breakPoint4, then went out. It is obvious that the actionSheet has been presented twice, that cause the problem. It is odd, and I do not know the reason and avoid this.

在另一个问题中解决的问题UILongPressGestureRecognizer被称为按下两次

感谢@ Laddu,@ MichaelDautermann,@ sreecharan

thanks to @Laddu, @MichaelDautermann, @sreecharan

推荐答案

在另一个问题中解决的问题UILongPressGestureRecognizer按下时被调用两次

Problem solved in another question UILongPressGestureRecognizer gets called twice when pressing down

感谢@ Laddu,@ MichaelDautermann,@ sreecharan

thanks to @Laddu, @MichaelDautermann, @sreecharan

这篇关于无法在此处关闭操作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆