UIAlertView删除不起作用

时间:2014-09-09 09:33:38

标签: ios objective-c ios7 uialertview

我正在尝试显示是/否警报视图并根据答案执行操作,但警报视图不会消失

我起诉的代码

UIAlertView *alert ;
- (void)GoOffline:(id)sender {


    alert = [[UIAlertView alloc] initWithTitle:@"Alert"
                                                    message:@"It will take time to download according to connection speed..Do you want to proceed?"
                                                   delegate:self
                                          cancelButtonTitle:@"No"
                                          otherButtonTitles:@"Yes", nil];
    [alert show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    dispatch_async(dispatch_get_main_queue(), ^{

        [alert removeFromSuperview];

    });
 // Handle yes No code    

}

我甚至试过了[alert removeFromSuperview];,但警告仍然停留在视图上,直到处理完/是没有代码完成,任何想法立即隐藏它

2 个答案:

答案 0 :(得分:0)

你的意思是你想以编程方式隐藏它吗?没有点击是或否?如果是,请尝试:

[alert dismissWithClickedButtonIndex:0 animated:YES]; 

//不要忘记在主线程中调用它(dispatch,performOnMainThread,...)

答案 1 :(得分:0)

您可以按照以下方式处理是或否

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
 if (buttonIndex == 0) 
{
    [alert removeFromSuperView]; //[alertView removeFromSuperView];(Handling NO)
}
else if (buttonIndex == 1)
{
    [alert removeFromSuperView]; //[alertView removeFromSuperView];(Handling YES)
}

}

Hope it helps you..!