UIAlertView需要时间显示 [英] UIAlertView taking time to show

查看:63
本文介绍了UIAlertView需要时间显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在按下按钮时显示警报视图.它已显示,但要花费太多时间才能在屏幕上显示.这是我按下按钮时要调用的功能:

I want to display an alert view on pressing a button. It is displayed but it takes too much time to be displayed on screen. here is the function that I am calling on pressing the button:

-(void)saveAndClose:(id)sender
{
    waitForOCR=[[UIAlertView alloc] initWithTitle:@"Processing..." message:@"Please wait." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
    waitForOCR.delegate=self;
    [waitForOCR show];
    if(!isCancelled){
    NSMutableArray *dateSaved=[[NSMutableArray alloc] initWithArray:[[NSUserDefaults standardUserDefaults] arrayForKey:@"dateCaptured"]];
    NSDateFormatter *dateText=[[NSDateFormatter alloc] init];
    [dateText setDateFormat:@"yyyy-MM-dd"];
    NSDate *now=[NSDate date];
    NSString *dateValue=[dateText stringFromDate:now];
    [dateSaved addObject:dateValue];
    NSMutableArray *timeSaved=[[NSMutableArray alloc] initWithArray:[[NSUserDefaults standardUserDefaults] arrayForKey:@"timeCaptured"]];
    NSDateFormatter *timeText=[[NSDateFormatter alloc] init];
    [timeText setDateFormat:@"HH:mm:ss"];
    NSString *timeValue=[timeText stringFromDate:now];
    [timeSaved addObject:timeValue];
    [[NSUserDefaults standardUserDefaults] setObject:dateSaved forKey:@"dateCaptured"];
    [[NSUserDefaults standardUserDefaults] setObject:timeSaved forKey:@"timeCaptured"];
    [dateSaved release];
    dateSaved=nil;
    [timeSaved release];
    timeSaved=nil;
    int counter = [[NSUserDefaults standardUserDefaults] integerForKey:@"LaunchesCounter"];
    counter++;
    [[NSUserDefaults standardUserDefaults] setInteger:counter forKey:@"LaunchesCounter"];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"image%d.png",counter]];
    NSData *thedata = [[NSData alloc] initWithData:UIImagePNGRepresentation(imageToCrop)];
    [thedata writeToFile:localFilePath atomically:YES];
    [thedata release];

    [NSThread detachNewThreadSelector:@selector(processOcrAt:) toTarget:self withObject:[self.imageCropper getCroppedImage]];
    }
    else{
        isCancelled=FALSE;
    }

}

您可以看到我在函数开始时显示 UIAlerView .但是显示时间太长.有任何解决此问题的建议吗?谢谢问候Idrees

As you can see that I am displaying UIAlerView at the start of the function. But it is taking too long to be displayed. Any suggestion to fix this issue? Thanks Regards Idrees

推荐答案

警报只会显示在当前运行循环的末尾,因此您在显示"警报后立即执行的所有操作实际上都将在此之前发生.请注意,无论如何都要将该代码移入后台是一个好主意,因为否则它将阻塞主线程并使应用程序最好没有响应.

The alert will only show up at the end of the current run loop, so everything you do right after "showing" it, will actually happen before. Note that it would be a good idea to move that code into the background anyway, as it will otherwise block the main thread and make the app unresponsive at best.

这篇关于UIAlertView需要时间显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆