Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

gtenrreiro

macrumors newbie
Original poster
Oct 23, 2012
3
0
Hi,

We are testing a simple app where a few labels and a UIProgressView is updated using a delay.

The delay is 3 seconds and then it calls itself again; however the IOS simulator does not always update the label, it does update sometimes but it takes a long time in between ( much long than 3 seconds ):

label.text = @"Some text";

We have a NSLog call where the update happens, and the NSLog fires just fine, exactly every 3 senconds, but the labels and ProgressView go unchanged until later.

Does anyone know what is going on ?

THanks
 
Are you updating the labels on the main thread?

Also, it is a simulator, and accurate timing is not guaranteed on it (it will never be accurate even on the iOS device).
 
I don't think they are being updated on the main thread, because the update happens as the consequence of a:

[NSURLConnection sendAsynchronousRequest...

to which a block of code is attached that gets executed when the request succeeds; so since it is asynchronous the code being execute must be running in its own thread. The block being executed however does fire exactly every 3 seconds, it is just UI components that act as if the code didn't execute at that time.

I understand it is a simulator, and that it is not real time, but the difference between the changes to the UI components and the when they actually occur is huge, sometimes 5 seconds sometimes more.

I appreciate your help.

Thanks
 
I don't think they are being updated on the main thread, because the update happens as the consequence of a:

[NSURLConnection sendAsynchronousRequest...

to which a block of code is attached that gets executed when the request succeeds; so since it is asynchronous the code being execute must be running in its own thread. The block being executed however does fire exactly every 3 seconds, it is just UI components that act as if the code didn't execute at that time.

I understand it is a simulator, and that it is not real time, but the difference between the changes to the UI components and the when they actually occur is huge, sometimes 5 seconds sometimes more.

I appreciate your help.

Thanks

You should update UI elements only in the main thread. UIKit is not thread safe.
 
Thanks, OK I resolved the issue by instead of creating a new queue:

NSOperationQueue* queue = [[NSOperationQueue alloc] init];

getting a reference to the main queue which runs in the main thread:

NSOperationQueue* queue = [NSOperationQueue mainQueue];

Not sure if this is the correct approach but it seems to work now.

Thanks
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.