How can I display a waiting progress bar before the application started on an IPhone

只愿长相守 提交于 2019-12-25 08:25:51

问题


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.


回答1:


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 & Default@2x.png. If 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.

Edit: 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]];
}



回答2:


Place a loading bar in the first screen and start your computation-heavy code in another thread after displaying it.



来源:https://stackoverflow.com/questions/9902496/how-can-i-display-a-waiting-progress-bar-before-the-application-started-on-an-ip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!