防止在iPad上意外解雇UIActionSheet

时间:2012-09-07 12:47:02

标签: ios ipad ios5 uiactionsheet

我正在使用UIActionSheet在iPad应用中向用户提供两个选项。用户选择一个或其他选项,UIActionSheetDelegate处理其余选项。但是,如果用户意外轻触iPad屏幕上的任何其他位置,则会自动关闭UIActionSheet,并且不会选择这两个选项。如何防止UIActionSheet自动解除,因此用户被迫选择其中一个选项?

3 个答案:

答案 0 :(得分:0)

如果操作表位于UIPopover内,则解决方法是使用UIPopoverDelegate阻止弹出窗口在操作表存在时解除。另一种解决方案是使用UIAlertView,除了与警报交互外,不允许任何事情发生。可能不是你的解决方案。如果您触摸屏幕的其他部分,我不知道UIActionSheet会以任何其他方式解散自己。

为操作表可见时创建BOOL变量

BOOL actionSheetVisible; //in header file

//in @implementation file
-(void)displayAlert {
    actionSheetVisible = YES;
    //code to display UIAction sheet...
}

#pragma mark PopoverControllerDelegate method
-(BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popover {
    if (actionSheetVisible) {
        return NO;
    }
    return YES;
}

#pragma mark UIAlerViewDelegate
...actionSheet:(UIActionSheet *)sheet selectedObjectAtIndex:(NSUInteger)index { ... //not sure what this method is at the moment
    actionSheetVisible = NO;
    //handle action sheet
}

答案 1 :(得分:0)

如何在不执行任何操作的应用程序窗口中添加手势控制器?或者尝试将其添加到工作表下方的视图中?完成后务必将其删除;)

答案 2 :(得分:0)

我会抛出另一个想法 - 在您显示操作表之前,添加一个覆盖整个屏幕的透明视图到窗口,并设置视图。 userInteractionEnabled = NO,然后在取消操作表时删除视图。 [我没有在iPad上测试过,但在手机上使用了这种技术]

相关问题