ActionSheet导致多个Popovers在iPad上显示

时间:2012-08-20 22:56:58

标签: objective-c ios ios-universal-app

我有一个通用应用程序,并有一个带有几个按钮的操作表。当我点击添加按钮(navigationItem.right)时,我希望它以popoever显示。它正确地执行了此操作,但是,将actionSheet绑定到barbutton项,它允许我不断点击添加按钮并有更多弹出窗口。

我认为在弹出窗口外面敲击会解雇这个......

- (IBAction)ShowItemAdd:(id)sender
{
    addActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:[dataObj.preferences objectForKey:@"appts_name"], @"Reserve", nil];
    if ([[UIDevice currentDevice] isPad]) {
        [addActionSheet showFromBarButtonItem:[[self navigationItem] rightBarButtonItem] animated:YES];
    } else {
        [addActionSheet showInView:self.view];
    }
}

如果我将它绑定到barbutton项目,为什么这不会自动解除?

修改

点击顶部navigationItem栏(蓝色条)中的任何位置都不会关闭actionSheet,但是在导航控制器外部点击将关闭操作表。

enter image description here

1 个答案:

答案 0 :(得分:1)

在您的方法中,您应首先检查您的操作表是否已经显示,如果是,则将其关闭,而不是创建新的操作表。

- (IBAction)ShowItemAdd:(id)sender
{
    if ([addActionSheet isVisible]) {

        [addActionSheet dismissWithClickedButtonIndex:[addActionSheet cancelButtonIndex] animated:YES];

    } else {

        addActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:[dataObj.preferences objectForKey:@"appts_name"], @"Reserve", nil];
        if ([[UIDevice currentDevice] isPad]) {
            [addActionSheet showFromBarButtonItem:[[self navigationItem] rightBarButtonItem] animated:YES];
        } else {
            [addActionSheet showInView:self.view];
        }
    }
}