可以删除以前的警报视图吗?

时间:2014-01-11 10:23:07

标签: ios uialertview

我在一个方法中创建了两个 UIAlertView 视图。代码如下

-(void) alert{
UIAlertView *alert_1 = [[UIAlertView alloc] initWithTitle:@"Message" message:@“Alert 1” delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert_1 show];

UIAlertView *alert_2 = [[UIAlertView alloc] initWithTitle:@"Message" message:@“Alert 2” delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert_2 show];
}

调用此方法后。 iPhone应用程序将弹出2次。

首先显示为 alert_1 ,消失 alert_1 并显示 alert_2

用户在 alert_2 中按下确定按钮后出现 alert_1

出现 alert_2 时应

删除 alert_1

是否可以删除以前的提醒视图?

4 个答案:

答案 0 :(得分:4)

向alert1发送消息- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated

答案 1 :(得分:2)

UIAlertView *alert_1 = [[UIAlertView alloc] initWithTitle:@"Message" message:@“Alert 1” delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert_1 show];
[alert_1 dismissWithClickedButtonIndex:0 animated:YES];
UIAlertView *alert_2 = [[UIAlertView alloc] initWithTitle:@"Message" message:@“Alert 2” delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert_2 show];

答案 2 :(得分:0)

我不清楚你的要求是什么。但根据我的理解,您希望alert_2首先弹出,当您单击“确定”按钮时,您想要关闭该警报视图并弹出alert_1

- (void) alertview
{
    alert_1 = [[UIAlertView alloc] initWithTitle:@"Alert 1" message:@"Message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert_1 setTag:1];
    alert_1.delegate = self;

    alert_2 = [[UIAlertView alloc] initWithTitle:@"Alert 2" message:@"Message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert_2 setTag:2];
    alert_2.delegate = self;
    [alert_2 show];
}

- (void) alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
   if (alertView.tag ==2)
   {
    [alert_1 show];
   }
}

请注意在.h文件中声明您的提醒视图

答案 3 :(得分:0)

通过其标记或@Property获取UIAlertView并使用此[myAlertView dismissWithClickedButtonIndex:-1 animated:YES];