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: Nick Rogers <email@hidden>
- Date: Fri, 04 Mar 2011 13:24:25 +0530
Hi,
Thanks for the reply.
But the problem is that I don't have anything common in the rows.
The image (128x128) are different, the four lines of text are different and the lines I draw are different in each cell.
Any Ideas?
Regards,
Nick
On 03-Mar-2011, at 9:48 PM, email@hidden wrote:
>
> 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
_______________________________________________
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