UIActionSheet from UIAlertView

2019-07-07 02:15发布

I'm trying to show a UIActionSheet when the user touches a button in a UIAlertView:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{
    if (buttonIndex == 0)
    {
        UIActionSheet *actionSheet = ...
        [actionSheet showFromTabBar:self.tabBarController.tabBar];
    }
}

When the action sheet is shown the alert view is still on the screen behind the action sheet, and when I touch a button in the action sheet - the action sheet disappears but the whole screen is dimmed with the alert view still on and I can't dismiss it.

I tried several things, such as showing the action sheet after a short delay or dismissing the alert view programmatically, but nothing worked. In the best case (dismissing the alert view programmatically) the alert view did disappear after a somewhat-strange transition but I got a "wait-fence failed to receive reply" error in the log when it did.

How can I show an action sheet from an alert view in an orderly manner?

2条回答
We Are One
2楼-- · 2019-07-07 02:48

Just call dismissWithClickedButtonIndex:animated: method for UIAlertView

if (buttonIndex == 0)
{
    [alertView dismissWithClickedButtonIndex:0 animated:YES];
    UIActionSheet *actionSheet = ...
    [actionSheet showFromTabBar:self.tabBarController.tabBar];
}
查看更多
冷血范
3楼-- · 2019-07-07 03:00

In this case, you should use

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex

method rather than,

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

so your code wil be:

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0)
    {
        UIActionSheet *actionSheet = ...
        [actionSheet showFromTabBar:self.tabBarController.tabBar];
    }
}

Thanks,

查看更多
登录 后发表回答