Reputation: 1395
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.
Upvotes: 0
Views: 5059
Reputation: 3824
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].
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]];
}
Upvotes: 2
Reputation: 8147
Place a loading bar in the first screen and start your computation-heavy code in another thread after displaying it.
Upvotes: 0