views:

58

answers:

2

I'm trying to create a UILabel which will inform the user of what is going on while he waits. However the UILabel always delay its text update until after the system goes idle again.

The process:

[infoLine performSelectorOnMainThread:@selector(setText:) withObject:@"Calculating..." waitUntilDone:YES];
[distanceManager calc]; // Parses a XML and does some calculations
[infoLine performSelectorOnMainThread:@selector(setText:) withObject:@"Idle" waitUntilDone:YES];

Should not waitUntilDone make this happen "immediately"?

A: 

Yes waitUntilDone makes the setText: happen immediately, but setting the label's text does not mean the screen is updated immediately.

You may need to call -setNeedsDisplay or even let the main run loop tick once before the screen can be updated.

KennyTM
I've tried to use [infoLine setNeedsDisplay]; but nothing happens. How can I wait for the main loop to tick once before running distanceManager?
ciffa
+2  A: 

If you are doing this on the main UI thread, don't use waitUntilDone. Do a setText, setNeedsDisplay on the full view, set a NSTimer to launch what you want to do next starting 1 millisecond later, then return from your function/method. You may have to split your calculation up into chucks that can be called separately by the timer, maybe a state machine with a switch statement (select chunk, execute chunk, increment chunk index, exit) that gets called by the timer until it's done. The UI will jump in between your calculation chunks and update things. So make sure your chunks are fairly short (I use 15 to 200 milliseconds).

hotpaw2
It works! Thanks!
ciffa
You're welcome.
hotpaw2