Re: NSTableView, NSArrayController, and ImageAndTextCell
Re: NSTableView, NSArrayController, and ImageAndTextCell
- Subject: Re: NSTableView, NSArrayController, and ImageAndTextCell
- From: mmalcolm crawford <email@hidden>
- Date: Fri, 7 Nov 2003 23:47:36 -0800
On Nov 7, 2003, at 9:11 PM, Kurt Marek wrote:
I'm trying to get an icon next to the text in my tableView. I've
downloaded Apple's ImageAndTextCell and I'm trying to get it to work
with a tableView that is bound to an NSArrayController. I haven't been
able to get it to work yet; has anyone else had success with this?
It's unlikely to work in a simple implementation.
The ImageAndText cell requires two variables to be set; you can only
bind a single value. If the value contained both the text and the
image (for example in a dictionary) that would work (assuming the
ImageAndTextCell knew the keys to use to extract the information from
the dictionary).
Here's the strategy I'm trying. The NSArrayController controls an array
of custom classes consisting of two instance variables: objectTitle and
objectITCell (an instance of the ImageAndTextCell). I bound the column
in my tableView to NSArrayController selection.objectITCell. I can set
the image in the objectITCell instance programatically and I can get
the table to add records and edit the cell, but I can't get the cell to
display the image and the text. Although I assumed that setting up the
binding this way would tell the column to expect this specialized cell
type, I also tried to set it manually:
Sorry, it's not clear what you're intending to do here. If you bind
the value of table column to a cell, then all that will happen is that
the existing textfield cell will try to display a string representation
of the cell -- or somesuch. As with the outline view example, you have
to set the datacell programatically, as you do here:
NSTableColumn *tableColumn = nil;
ImageAndTextCell *imageAndTextCell = nil;
tableColumn = [sourceTableView tableColumnWithIdentifier: @"Source"];
imageAndTextCell = [[[ImageAndTextCell alloc] init] autorelease];
[imageAndTextCell setEditable: YES];
[tableColumn setDataCell:imageAndTextCell];
Notice from the outline view example that the image is set
independently of the text:
- (void)outlineView:(NSOutlineView *)olv willDisplayCell:(NSCell *)cell
forTableColumn:(NSTableColumn *)tableColumn item:(id)item {
if ([[tableColumn identifier] isEqualToString: COLUMNID_NAME]) {
// Make sure the image and text cell has an image. If not, give it
something random.
if (item && ![NODE_DATA(item) iconRep]) [NODE_DATA(item) setIconRep:
[self _randomIconImage]];
// Set the image here since the value returned from
outlineView:objectValueForTableColumn:... didn't specify the image
part...
[(ImageAndTextCell*)cell setImage: [NODE_DATA(item) iconRep]];
// ...
You can adopt the same strategy with the tableview too, if you want:
<
http://homepage.mac.com/mmalc/CocoaExamples/ImageAndTextCell.zip>
however I'm not sure how well this will play with the controller's
arrragnedObjects...
mmalc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.