I'm currenlty developing a simple test software for iPhone that use only an UILabel and an UIButton. The button is linked to the "writeresult" action that contains the following code:
The problem is that when the user tap the button, it will show only the last number. The label doesn't appear with the value increasing (i think, it doesn't "reload" its content) and the software seems like freezing during the cycle (no user interaction till the loop ending).
How to show updated text in the UILabel when "i" increase (ie: "Number: 1" then "Number: 2" .... etc) ?
while (i<1000)
labelOutput.text = [labelOutput.text stringByAppendingFormat:@"Number: %d ", i++];
i++ will not be performed until after that line of code is executed so you should get your expected results
Generally you have to allow your apps to get into the run loop for UI elements to be updated. Never write any functions that will take too long unless you do them with NSOperation or multithreaded.
A easy way around this is to do the updating in NSTimer method.
__________________
regards
Oliver Drobnik Cocoanetics - Our DNA is programmed in Objective-C.
Cocoanetics Parts Store – easy to use yet professionally looking components that you can use to spruce up your own apps. Augmented Reality, Calendar Control, Pin Lock or Purchase Button are only some examples. You get full source code, no static library crap, and lifetime support. Check it out today!
Yes Oliver is right, for some reason I thought you were trying to add onto the string. NSTimer seems like your best option because you probably want it to update the display at some set interval such as 1 second.
Generally you have to allow your apps to get into the run loop for UI elements to be updated. Never write any functions that will take too long unless you do them with NSOperation or multithreaded.
A easy way around this is to do the updating in NSTimer method.
You're right :-)
I've read the NSTimer description in the xcode documentation but I didn't understand how to use it .. I'm a newbie with objective - c :-P
where fooLabel is a new UILabel with the same declaration of labelOutput.
But it doesn't behave how I would .. it shows the 999 number (the last "i" value) yet and the string in fooLabel AFTER the ending of the while loop..:-(
where fooLabel is a new UILabel with the same declaration of labelOutput.
But it doesn't behave how I would .. it shows the 999 number (the last "i" value) yet and the string in fooLabel AFTER the ending of the while loop..:-(
You also need to move the incrementing to the testFunction!
__________________
regards
Oliver Drobnik Cocoanetics - Our DNA is programmed in Objective-C.
Cocoanetics Parts Store – easy to use yet professionally looking components that you can use to spruce up your own apps. Augmented Reality, Calendar Control, Pin Lock or Purchase Button are only some examples. You get full source code, no static library crap, and lifetime support. Check it out today!
Cocoanetics Parts Store – easy to use yet professionally looking components that you can use to spruce up your own apps. Augmented Reality, Calendar Control, Pin Lock or Purchase Button are only some examples. You get full source code, no static library crap, and lifetime support. Check it out today!
is that code you put in the testFunction within the while loop? Could you provide the whole tesFunction code, I couldn't figure out how you get it to work. I probably misunderstood somewhere.