How to repeat NSView's -drawRect method? (noob)

Discussion in 'Mac Programming' started by rerelease, May 22, 2010.

  1. rerelease macrumors regular

    Joined:
    Jun 8, 2009
    Location:
    eesti
    #1
    I'm trying to build my first graphical app that utilizes NSRects and NSPoints to draw a very basic clock into a custom MyView.

    Thus far the result looks like this:
    [​IMG]

    However, the clock is static and as such not very impressive. How could I make my custom NSView object call the -drawRect method repeatedly (every once a second)? Is there any easy way to do it?

    Keep in mind that I have very little idea of what I'm doing and the code is really basic so baby steps would be useful. :)

    Thanks for your help!
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    You can use NSTimer. In your custom view somewhere, create it like so:

    Code:
    [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(redraw) userInfo:nil repeats:YES];
    Then setup the timer's action method to redraw the view:

    Code:
    - (void)redraw
    {
        [self setNeedsDisplay:YES];
    }
    
     
  3. rerelease thread starter macrumors regular

    Joined:
    Jun 8, 2009
    Location:
    eesti

Share This Page