Objective c 在空白的开始和结束处显示警报视图

Objective c 在空白的开始和结束处显示警报视图,objective-c,Objective C,我有空。这个虚空做了一些非常缓慢的事情,所以在虚空的开始我放了一个警报,最后我放了另一个警告。就像这里: -(void)action { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Start" message:@"Start." delegate:self cancelButtonTitle:@"Ok." otherButtonTitles:nil]; [alerta show]; [alert release]; //

我有空。这个虚空做了一些非常缓慢的事情,所以在虚空的开始我放了一个警报,最后我放了另一个警告。就像这里:

-(void)action {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Start" message:@"Start." delegate:self cancelButtonTitle:@"Ok." otherButtonTitles:nil];
[alerta show];
[alert release];

//Something really slow

    UIAlertView *alertEnd = [[UIAlertView alloc] initWithTitle:@"End" message:@"End." delegate:self cancelButtonTitle:@"Ok." otherButtonTitles:nil];
[alertEnd show];
[alertEnd release];
}
但当我运行这段代码时,警报只会在所有缓慢的操作之后显示在空白的末尾


如何解决此问题?

您必须将这两种方法分为两种,然后使用

[self performSelector: afterDelay:]

方法

首先:尽量避免使用许多警报,因为这对用户来说不人道。改为显示UIActivityIndicator

如果必须,请尝试以下代码以显示第一个警报:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Start" message:@"Start." delegate:self cancelButtonTitle:@"Ok." otherButtonTitles:nil];

[alert performSelector: @selector(show)
              onThread: [NSThread mainThread]
            withObject: nil
         waitUntilDone: NO];  

谢谢!!还有一件事:我将使用UIActivityIndicator.:-)