1

我一个接一个地显示两个警报视图,如下所示:

-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 但实现它是我可以使用一些建议的地方。

4

2 回答 2

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 
});
于 2012-07-14T13:54:37.860 回答
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];
}
于 2014-03-15T11:25:42.787 回答