views:

43

answers:

1

As a practical example, in UIView, drawRect is called when setNeedsDisplay is set. I want a different drawRect routine to be called for the first time vs. the subsequent update. So for example, I want drawRect to call drawRectFirstTime for the first time and drawRect to call drawRectSubsequentUpdate for subsequent setNeedsDisplay.

How should this be done in Objective-C?

+3  A: 

From top of my head:

- (void)drawRect:(NSRect)rect
{
   static BOOL first = YES;
   if (first == NO)
   {
      [self drawRectSubsequentUpdate:rect];
   } else {
      [self drawRectFirstTime:rect];
      first = NO
   }
}
stefanB
This only works for one UIView object. I presume the OP wanted a solution that works on all objects, not just the first one.
Adam Rosenfield
The more complicated requirements the more complex the solution.
stefanB
Thanks stefanB. Sorry this is not what I am looking for. The whole point of asking how to modify the dispatch table is to avoid doing the if-else check in drawRect.
Boon