如何在呈现第二个警报视图之前添加延迟

时间:2012-07-14 13:52:41

标签: ios uialertview

我依次连续显示两个警示视图:

-IBAction

UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"my message"     delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert setDelegate:self];

[alert show];




}

- (void)didPresentAlertView:(UIAlertView *)alertView 
{

[alertView setTitle:@"My new title"];
[alertView setMessage:@"My new message"];

}

从第一个警报视图到第二个警报视图的转换速度非常快,用户没有时间阅读第一条消息。有人可以建议如何在警报之间添加延迟。我想我需要实现一个NSTimer,但实现这个我可以使用一些建议。

2 个答案:

答案 0 :(得分:13)

我建议使用dispatch_after,可以内联:

double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
     // code to be executed on the main queue after delay 
});

答案 1 :(得分:0)

尝试这个简单的方法:

- (void)alertView
{
    UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"Get Ready!" message:nil     delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
    [alertView show];
    [self performSelector:@selector(dismissStartAlert:) withObject:alertView afterDelay:5];
}

-(void)dismissStartAlert:(UIAlertView *)alertView
{
    [alertView dismissWithClickedButtonIndex:0 animated:YES];
    [alertView setTitle:@"My new title"];
    [alertView setMessage:@"My new message"];
    [alert show];
}