You must learn NSOperation ; either NSInvocationOperationif you have a specific rendering object, or NSBlockOperationif the rendering is simple enough to fit into a single function.
If you can start rendering before moving on to your view drawRect:, do it (maybe your application delegate will start the process right away when it starts). Otherwise, check drawRect:if the content is available; if not, start the operation and continue working with another drawing. When the rendering object completes its work, it will probably either post a notification, or if you return a link to the view, callsetNeedsDisplay:
, . , ( n n ), NSImage , ( ), .
: NSImage "" setNeedsDisplay: , . , , ; , "" - . initByReferencingURL:, URL-, , (, , ) , , , initWithURL:, . ; , , .
NSImage ; , , , , "renderer", NSImage.
MORE:
drawRect:
- (void)drawRect:(NSRect)dirtyRect {
NSLog(@"Entered: %@", NSStringFromSelector(_cmd));
NSImage * lazyImage = [[[NSImage alloc] initByReferencingURL:
[NSURL URLWithString:@"http://www.eso.org/public/archives/images/original/milkyway.jpg"]]
autorelease];
NSLog(@"Image instantiated.");
[lazyImage drawInRect:[self bounds] fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0];
NSLog(@"Image drawn");
[[NSColor yellowColor] set];
[[NSBezierPath bezierPathWithRect:NSInsetRect([self bounds], 4, 4)] stroke];
NSLog(@"Bezier path drawn; exiting drawRect.");
}
; , , , , ( ):
2011-04-27 21:33:00.899 SetNeedsDisplay[80162:a0b] Entered: drawRect:
2011-04-27 21:33:00.901 SetNeedsDisplay[80162:a0b] Image instantiated.
2011-04-27 21:34:57.911 SetNeedsDisplay[80162:a0b] Image drawn.
2011-04-27 21:34:57.912 SetNeedsDisplay[80162:a0b] Bezier path drawn; exiting drawRect.