一个UILongPressGestureRecognizer已添加到具有action handleLongPressOnPhotos的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之后,我遵循了代码的步骤。步骤顺序为:中断点1->中断点2->中断点1->中断点2->中断点3->中断点4->中断点3->中断点4,然后熄灭。显而易见,actionSheet已被显示两次,从而导致了问题。这很奇怪,我不知道原因,避免这种情况。
在另一个问题中解决了问题UILongPressGestureRecognizer gets called twice when pressing down
感谢@ Laddu,@ MichaelDautermann,@ sreecharan
最佳答案
它看起来不错,但请在此处添加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委托。
关于iphone - 无法在此处关闭操作表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10511047/