使用动作handleLongPressOnPhotos将UILongPressGestureRecognizer添加到我的imageView。最相关的代码如下:
- (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
}
}
单击“保存照片”按钮后,操作表将不会被解除。如果我再次单击该按钮,操作表将被解除,照片会保存两次。代码中有任何问题吗?提前谢谢!
聚苯乙烯。 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之后,我按照代码的步骤进行操作。步骤顺序是:breakPoint1 - > breakPoint2 - > breakPoint1 - > breakPoint2 - > breakPoint3 - > breakPoint4 - > breakPoint3 - > breakPoint4,然后出去了。很明显,actionSheet已经呈现两次,导致问题。这很奇怪,我不知道原因并避免这种情况。
其他问题解决了问题 UILongPressGestureRecognizer gets called twice when pressing down
感谢@Laddu,@ MichaelDautermann,@ sreecharan答案 0 :(得分:1)
看起来不错,但请在此处添加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;
}
}
检查您是否也在.h文件中添加ACtionSheet Delegate。
答案 1 :(得分:0)
您有没有使用actionSheet:willDismissWithButtonIndex:
代替actionSheet:clickedButtonAtIndex:
的原因。
如果您使用actionSheet:willDismissWithButtonIndex:
,则无需自行解雇ActionSheet。
答案 2 :(得分:0)
另一个问题解决了问题UILongPressGestureRecognizer在按下时被调用两次
感谢@Laddu,@ MichaelDautermann,@ sreecharan