Re: Table view containing cells with both an image and text
Re: Table view containing cells with both an image and text
- Subject: Re: Table view containing cells with both an image and text
- From: Corbin Dunn <email@hidden>
- Date: Wed, 10 Dec 2008 13:41:30 -0800
On Dec 10, 2008, at 1:14 PM, Randall Meadows wrote:
On Dec 10, 2008, at 1:41 PM, Corbin Dunn wrote:
On Dec 10, 2008, at 11:54 AM, Eric Gorr wrote:
I need a column in my NSTableView with cells that contain both an
image and some text.
My first inclination is to subclass NSCell and have my subclass
manage both a NSImageCell and a NSTextFieldCell. Basically, I
would imagine would override:
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
and have it call drawWithFrame on the internal image cell and text
cell with the appropriate frames.
Then, assuming I am on the right track, is it also then correct
that what
- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn*)aTableColumn row:
(NSInteger)rowIndex
would return is what NSCell's setObjectValue gets called with?
Can't think of any reason why this wouldn't be the case...
Yeah, you are right, that is the case.
However, I'd recommend subclassing NSTextFieldCell and having it
draw an image. It'll make other stuff work for you automatically
(cell expansion tooltips, type selection). See: <http://developer.apple.com/samplecode/PhotoSearch/
>
I'm working through this exact thing right now. Couple things I
noticed:
- that example uses an NSOutlineView instead of an NSTableView, but
close enough, withsome translation...
- the cellFrame passed into -drawInteriorWithFrame:inView: is not
really the interior of the frame; I've had to do
No; it really is!
cellFrame.origin.x -= 1, cellFrame.origin.y -= 1,
cellFrame.size.width += 3, cellFrame.size.height += 1;
Yeah, you don't want to do this; you will have re-draw issues when the
cell is invalidated. It sounds like you want to set the -
intercellSpacing to 0,0, or override the -drawRow/drawRect method and
first fill in the area with a solid background color.
Essentially, what you are doing is undoing the intercell spacing.
to actually completely fill the cell, otherwise I get a white border
around the edges (since I'm filling the cell with a custom dark
color). I gather I must be doing something wrong, or not doing
something I should be, but doing the above completely fills the cell
whereas the default value doesn't.
One additional question I have (sorry, Eric, don't mean to hijack
your thread): in my -drawInterior... method, I draw an attributed
string with an NSFont attribute of "LucidaGrande-Bold 13.00 pt. P []
(0x16b8c4e0) fobj=0x16b8c450, spc=4.28", however, it sure looks like
it's drawing in non-bold, instead. I compared it with a
LucidaGrande-Bold 13 point sample in TextEdit, and it's vastly
different. I could see something changing behind my back when I
simply pass an attributed string back as the object value, but how
is that being done when I'm drawing it explicitly?
I don't know what is wrong off the top of my head, sorry!
corbin
attrs = [NSDictionary dictionaryWithObjectsAndKeys:
NSFontAttributeName, [NSFont boldSystemFontOfSize:13.0],
NSBackgroundColorAttributeName, [NSColor blackColor],
nil];
nameRect = NSInsetRect(cellFrame, 2, 0);
attrStr = [[NSAttributedString alloc] initWithString:name
attributes:attrs];
[attrStr drawInRect:nameRect];
Screenshot of this (blue) versus TextEdit: <http://www.not-pc.com/LucidaGrande-13.png
>
_______________________________________________
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