Re: table view and custom cell optimization problem
Re: table view and custom cell optimization problem
- Subject: Re: table view and custom cell optimization problem
- From: "email@hidden" <email@hidden>
- Date: Thu, 03 Mar 2011 16:18:49 +0000
On 3 Mar 2011, at 04:06, Nick Rogers wrote:
> Hi,
> I have a table view with the custom cell class assigned to its only column in awakeFromNib method using setDataCell:.
> Then I'm doing some drawing in drawInteriorWithFrame: of the NSCell subclass.
> The problem is that drawing include four lines of text and an image and a few lines using NSBezierPath.
>
> This is relatively time consuming and hence when I scroll the table view, the scrolling is not that smooth and is a bit jerky.
>
> Is there a way to do all this custom drawing in a manner that could make the scrolling faster.
I use the following approach in an NSView but you can adapt it.
The idea is to cache your background (that is common to all cells) in an NSImage instance.
When the cell needs drawn you copy from the image cache into your focus locked view.
Then you can draw the unique cell content - text etc.
Obviously when the cell size changes you have to regenerate your background image cache.
- (void)drawRect:(NSRect)rect
{
if (!_imageCache) {
// draw to image cache
_cacheRect = [self bounds];
_imageCache = [[NSImage alloc] initWithSize:_cacheRect.size];
[_imageCache lockFocus];
// draw background with beziers etc
[_imageCache unlockFocus];
}
[_imageCache drawInRect:rect fromRect:rect operation:NSCompositeSourceOver fraction:1.0f];
// now draw unique foreground
}
Regards
Jonathan Mitchell
Developer
Mugginsoft LLP
http://www.mugginsoft.com_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden