UIActionSheet from UIAlertView

☆樱花仙子☆ 提交于 2019-12-12 16:12:09

问题


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?


回答1:


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,




回答2:


Just call dismissWithClickedButtonIndex:animated: method for UIAlertView

if (buttonIndex == 0)
{
    [alertView dismissWithClickedButtonIndex:0 animated:YES];
    UIActionSheet *actionSheet = ...
    [actionSheet showFromTabBar:self.tabBarController.tabBar];
}


来源:https://stackoverflow.com/questions/8307700/uiactionsheet-from-uialertview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!