timed/scheduled event function

Discussion in 'Mac Programming' started by Hot Sauce79, Jul 28, 2008.

  1. Hot Sauce79 macrumors newbie

    Joined:
    Jul 1, 2008
    #1
    Hi again everyone,

    Now im trying to figure out how to run a function every time a certain amount of time has elapsed. I have tried using the NSTimer function but it does not seem to run my code.

    The code i want it to run changes the Array's that I had talked about in a previous thread and i want it to run once every second or something like that.

    When i run the code with NSTimer it does not redraw the screen that i want it to redraw. It just sits on the screen unchanged and stares at me.

    Any suggestions/help would be greatly appreciated!
     
  2. liptonlover macrumors 6502a

    Joined:
    Mar 13, 2008
    #2
    I just made a thread because I was trying to get NSTimer to work... it's still in the first page of mac programming, it's just called NSTimer. I posted my original code, people pointed things out, I responded, and finally I posted the working code. Learn from it :) I can now say I know how to use NSTimer!
     
  3. Krevnik macrumors 68030

    Krevnik

    Joined:
    Sep 8, 2003
    #3
    Well, two quick things to try here is:

    A) Set a breakpoint in your code that is supposed to be called when the timer triggers. Make sure the breakpoint gets hit.

    B) Look at the code to make sure the UI is being told to update. Just changing data won't cause a refresh unless someone is actually watching it and gets notified of it.
     
  4. Hot Sauce79 thread starter macrumors newbie

    Joined:
    Jul 1, 2008
    #4
    Ok i figured out what i had wrong with my timer so now it works. It turns out I was accidently invalidating it before I even used it >.< But my problem seems to run a little bit deeper than that.

    My screen still isnt updating and i checked using breakpoints and it is hitting the code that should be updating my screen.

    It is going through all of the code right and I am still adding breakpoints in different areas to make sure it is hitting them correctly

    Once again any and all help is appreciated!
     
  5. Hot Sauce79 thread starter macrumors newbie

    Joined:
    Jul 1, 2008
    #5
    Here is the code that I am trying to rerun that isnt running the way it should. I was thinking that maybe it is my problem.

    Code:
    spacey = 60;
    spacex = 20;
    	
    for(NSUInteger x=0;x<20;x++) {
    	for(NSUInteger y=0;y<10;y++) {			
    		[[[myArray objectAtIndex:x] objectAtIndex:y] drawAtPoint:(CGPointMake(spacey,spacex))];
    		spacey += 20;	
    	}
    	spacey = 60;
    	spacex += 20;
    }
    spacex = 20;
    

    According to the breakpoints the code is running fine, however the application is not changing its appearance at all.
     

Share This Page