• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTableView, NSArrayController, and ImageAndTextCell
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: NSTableView, NSArrayController, and ImageAndTextCell
      • From: Alastair Houghton <email@hidden>
References: 
 >NSTableView, NSArrayController, and ImageAndTextCell (From: Kurt Marek <email@hidden>)

  • Prev by Date: Re: NSTableView, NSArrayController, and ImageAndTextCell
  • Next by Date: Re: Controller Layer and Automatic Key-Value Observing
  • Previous by thread: Re: NSTableView, NSArrayController, and ImageAndTextCell
  • Next by thread: Re: NSTableView, NSArrayController, and ImageAndTextCell
  • Index(es):
    • Date
    • Thread