Refresh view since another thread...

Discussion in 'iOS Programming' started by bboyjayz, Mar 20, 2009.

  1. bboyjayz macrumors member

    Joined:
    Mar 20, 2009
    #1
    hi,
    i've got a problem, i've searched on the forum but my problem isn't resolved... so, i've got my main vieWcontroller, which create another thread to move a ball on the screen, without stop all event...
    my ball (an IBOutlet UIImageView) is on the class of the mainViewController, and its center is changed on the thread created... but it is not refesh on the screen... and when the program exite, i see just for 1 seconde, the ball on its new center... :s
    i don't know how to do... can you help me ???
     
  2. Jeremy1026 macrumors 68020

    Jeremy1026

    Joined:
    Nov 3, 2007
    #2
    Run a timer on the background thread to update the location of the ball on the main thread.
     
  3. bboyjayz thread starter macrumors member

    Joined:
    Mar 20, 2009
    #3
    hmm sorry but what do you meen by "Timer", i've never used that yet... :s

    PS: nice name...same as me (sorry for my english...i'm french)
     
  4. Jeremy1026 macrumors 68020

    Jeremy1026

    Joined:
    Nov 3, 2007
    #4
    NSTimer in the documentation should get you going.
     
  5. bboyjayz thread starter macrumors member

    Joined:
    Mar 20, 2009
    #5
    do you have an exemple of how to use NSTimer?
    for the moment, my code is like that:
    while(true){
    NSLog(@"coucou");
    CGPoint c = controller.ball.center;
    c.y--;
    [controller setBallCoordonnees:c];
    [NSThread sleepForTimeInterval:time];
    }

    contoller is on my main thread, setBallCoordonnee just change center of my ball, how can i refresh the screen ;.. that is the question :(
     
  6. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #6
    To redraw a view use:
    Code:
    [view setNeedsDisplay];
     
  7. bboyjayz thread starter macrumors member

    Joined:
    Mar 20, 2009
    #7
    thank you for your helps, i've resolved my problem, using NSTimer, with a tutorial doing exactly what i want my program do ... ^^
    thank youuu
     

Share This Page