English 中文(简体)
陷入混乱 2 UIActionSheets
原标题:Having trouble dismissing 2 UIActionSheets

我在UIToolbar有2个律师无国界组织。 每个组织都有一项行动,以启动自己的行动。

现在,如果我在场的话,那就点击了另一个“世界钻石组织”,另一个行动小组也做了介绍,因此,我有两个在屏幕上,它们重叠。 我想有人在提出对方时就予以驳回。

I have this code now:

- (IBAction)showFirstActionSheet:(id)sender
{
    if (!self.eRXActionSheet)
    {
        UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"eRX Menu" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"New eRX", @"eRX Refills", nil];
        sheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
        self.eRXActionSheet = sheet;
        [sheet release];

        [self.eRXActionSheet showFromBarButtonItem:sender animated:YES];

        return;
    }

    [self.eRXActionSheet dismissWithClickedButtonIndex:self.eRXActionSheet.cancelButtonIndex animated:YES];
    self.eRXActionSheet = nil;
}

- (IBAction)showSecondActionSheet:(id)sender
{
    if (!self.actionSheet)
    {
        UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Action Menu" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Help", @"Lock", @"Log Out", nil];
        sheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
        self.actionSheet = sheet;
        [sheet release];

        [self.actionSheet showFromBarButtonItem:sender animated:YES];

        return;
    }

    [self.actionSheet dismissWithClickedButtonIndex:self.actionSheet.cancelButtonIndex animated:YES];
    self.actionSheet = nil;
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (actionSheet == self.eRXActionSheet)
    {
        if (buttonIndex == 0)
        {
            [self erxButtonClicked];
        }
        else if (buttonIndex == 1)
        {
            [self erxRefillButtonClicked];
        }
    }
    else
    {
        if (buttonIndex == 0)
        {
            [self helpButtonClicked];
        }
        else if (buttonIndex == 1)
        {
            [self lockButtonClicked];
        }
        else if (buttonIndex == 2)
        {
            [self logOut];
        }
    }
}
最佳回答

In your code, before creating an action sheet, your are checking if the action sheet to be displayed is not nil. Logically, this will always evaluate to true.

相反,如果other action summary is not nil,你应当加以核对。 如果是的话,则予以驳回,并创造新的内容。

-(void)buttonForActionSheet1Clicked {
    if (actionSheet2 != nil) {
        // dismiss it
    }
    // show actionSheet1
}

-(void)buttonForActionSheet2Clicked {
    if (actionSheet1 != nil) {
        // dismiss it
    }
    // show actionSheet2
}

或者,你可以迫使用户在工具栏中首先在disabling上放弃本行动表。

问题回答

电话:dismissWithClickedButtonIndex:animated: on the actionsheet 你想要解职。

E.g. in showFirstActionSheet add this line to dismiss the other:

if(self.actionSheet) [self.actionSheet dismissWithClickedButtonIndex:<indexofCancelButton> animated:YES];




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签