NSTimer with delegation method

I'm trying to set up NSTimer on a delegate - I'm so new to objective-c, so I apologize if that doesn't make much sense. But I wrote:

animationTimer = [NSTimer scheduledTimerWithTimeInterval:(NSTimeInterval)((1.0 / 60.0) * animationFrameInterval) target:self.delegate selector:@selector(drawView) userInfo:nil repeats:TRUE];

Unfortunately, this just doesn't work. Can someone point me in the right direction? My mind has fried !!

+3
source share
2 answers

You are fine.

Just add a colon to the method name, i.e. @selector (drawView :). In addition, under objective-c, encoders use YES and NO.

+3
source

Most likely, the method signature for drawViewis incorrect. From the link of the NSTimer class:

. :

- (void)timerFireMethod:(NSTimer*)theTimer

, drawView :

- (void)drawView:(NSTimer*)theTimer
{
// Draw the view
}

, ( , "drawView" ):

animationTimer = [NSTimer scheduledTimerWithTimeInterval:(NSTimeInterval)((1.0 / 60.0) * animationFrameInterval) target:self.delegate selector:@selector(drawView:) userInfo:nil repeats:TRUE];

, , drawView ( , ). , ( ). , NSView, setNeedsDisplay, , NSView , NSView drawRect:. , , Objective-C, , . , setNeedsDisplay.

+4

Source: https://habr.com/ru/post/1730548/


All Articles