IOS Simulator slow to update UI components

Discussion in 'iOS Programming' started by gtenrreiro, Oct 23, 2012.

  1. gtenrreiro macrumors newbie

    Joined:
    Oct 23, 2012
    #1
    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
     
  2. CodeBreaker macrumors 6502

    Joined:
    Nov 5, 2010
    Location:
    Sea of Tranquility
    #2
    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).
     
  3. gtenrreiro thread starter macrumors newbie

    Joined:
    Oct 23, 2012
    #3
    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
     
  4. CodeBreaker macrumors 6502

    Joined:
    Nov 5, 2010
    Location:
    Sea of Tranquility
    #4
    You should update UI elements only in the main thread. UIKit is not thread safe.
     
  5. gtenrreiro thread starter macrumors newbie

    Joined:
    Oct 23, 2012
    #5
    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
     

Share This Page