Please ignore this cry for help as it turns out I made a bit of a
'school boy' error.

The line

[separator drawInRect:NSMakeRect(cellFrame.origin.x,
cellFrame.size.height - 10.0f, cellFrame.size.width, 2.0f)
                                fromRect:NSZeroRect
                               operation:NSCompositeSourceOver
                                fraction:1.0f];

Should read

[separator drawInRect:NSMakeRect(cellFrame.origin.x,
cellFrame.origin.y + cellFrame.size.height - 10.0f,
cellFrame.size.width, 2.0f)
                                fromRect:NSZeroRect
                               operation:NSCompositeSourceOver
                                fraction:1.0f];

Turns out the image was being drawn for each row, on in the same place
each time. Doh!

-Mic


---------- Forwarded message ----------
From: Mic Pringle <micprin...@gmail.com>
Date: 2009/3/31
Subject: Strange NSCell subclass issue ...
To: cocoa-dev <cocoa-dev@lists.apple.com>


Hi,

I have subclassed NSCell and implemented only the following method ...

- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
       NSImage *separator = [NSImage imageNamed:@"Separator.png"];
       [separator setScalesWhenResized:YES];
       [separator setFlipped:YES];
       NSGraphicsContext *context = [NSGraphicsContext currentContext];
       [context saveGraphicsState];
       NSImageInterpolation interpolation = [context imageInterpolation];
       [context setImageInterpolation:NSImageInterpolationHigh];
       [separator setSize:NSMakeSize(cellFrame.size.width, 2.0f)];
       [separator drawInRect:NSMakeRect(cellFrame.origin.x,
cellFrame.size.height - 10.0f, cellFrame.size.width, 2.0f)
                                fromRect:NSZeroRect
                               operation:NSCompositeSourceOver
                                fraction:1.0f];
       [context setImageInterpolation:interpolation];
       [context restoreGraphicsState];
}

I have then subclassed NSTableView and set the dataCell of the first
column to the above subclass.

All works fine, except for the fact that the image drawn (separator)
in the drawWithFrame method is only drawn in the very first cell. I
have three rows displayed in the table view, and can clarify this as I
can click on them and get the blue highlight.

Any ideas as to why this would only draw the first cell and not all three ?

Thanks

-Mic
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to