本文介绍了如何在iPhone上启动应用程序之前显示等待的进度栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

启动我在iPhone上编写的应用程序需要花费很长时间.我希望显示一个等待进度条以指示启动进度的百分比.谁能帮我?我是IOS开发的新手.

It takes a long to start up the application I write on an iPhone. I hope to display a waiting progress bar to indicate the percentage of the startup progress. Can anyone help me? I am new to the Development of IOS.

推荐答案

您不能.必须先启动应用程序,然后才能显示任何动态内容.加载第一个ViewController之后,您当然可以显示进度条并进行加载.在此之前,您只能显示静态图片Default.png&默认值@ 2x.png.如果您将繁重的工作延迟到-[ViewController viewDidLoad] -方法完成之后,您就可以在进行繁重的工作时显示任何类型的GUI.

You can't.The application needs to be started before you can show any dynamic content.After your first ViewController is loaded you can of course show a progress bar and do loading.Before that, you can only show a static image Default.png & [email protected] you delay the heavy loading to after your -[ViewController viewDidLoad]-method is finished you can show any kind of GUI while doing the heavy work.

本示例将在您的viewDidLoad中分离一个新线程并进行一些繁重的工作(在本例中为睡眠1秒),并更新一个 UIProgressView 并在睡眠10次时记录进度,将progressview的值增加0.1每次.

This example will detach a new thread in your viewDidLoad and do some heavy work (in this case sleep for 1 second) and update a UIProgressView and log the progress as it sleeps 10 times, incrementing the progressview with 0.1 each time.

- (void)viewDidLoad
{
 // .....
   [NSThread detachNewThreadSelector:@selector(workerBee) toTarget:self withObject:nil];
}

- (void)workerBee
{
    NSAutoreleasePool* workerPool = [[NSAutoreleasePool alloc] init];

    // Put your image loading between this line and [workerpool release]

    for (float i = 0; i<1; i+= 0.1)
    {
        [self performSelectorInBackground:@selector(updateProgress:) withObject:[NSNumber numberWithFloat:i]];
        sleep(1000);
    }
    [workerPool release];
}

- (void)updateProgress:(NSNumber*)number
{
    NSLog("Progress is now: %@", number);
    [progressView setProgress:[number floatValue]];
}

这篇关于如何在iPhone上启动应用程序之前显示等待的进度栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 19:09