• 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 custom cell problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTableView custom cell problem


  • Subject: Re: NSTableView custom cell problem
  • From: Andrew Skinner <email@hidden>
  • Date: Thu, 6 Jan 2005 20:47:42 +0000

Thanks j o a r

I didn't really mean hacking and I shouldn't have used the word but I have just tried so many variations and one made the text appear in the cell. The other weird thing is that I had to click on the cell first to make the text appear too. I didn't think this is the right way to do it and moved on.

What I did to make it (semi)work was this (please bear in mind I was getting desperate by this point):

<x-tad-smaller>- (void)tableView:(NSTableView *)view
willDisplayCell:(id)cell
forTableColumn:(NSTableColumn *)col
row:(int)row
{
if ([[col identifier] isEqualTo: @"name"]) {
feedCell *nameCell = [[feedCell alloc] init];
[col setDataCell:nameCell];
}
else if ([[col identifier] isEqualTo: @"icon"])
{
[cell setImage:[NSImage imageNamed: @"Picture"]];
}
}</x-tad-smaller>


Part of the problem may be something to do with copying the subclass as I didn't allow for that.

[cell representedObject];

This just returns the cells object value. Something else I thought i'd try.

Thanks in advance

a

On 6 Jan 2005, at 18:24, j o a r wrote:

On 2005-01-06, at 18.41, Andrew Skinner wrote:

However when I try and use the NSCell subclass in my tableview it doesn't work, with a bit of hacking

What type of hacking?

i can get it to appear in the table view but only in the first cell and each new item I add to my datasource the first cell gets overwritten with another instance of the cell.

Expect the table view to sometimes create copies of your cell. Make sure that your cell subclass can be copied.

//Set up image cell
cell = [NSImageCell new];
[theIconColumn setDataCell:cell];


//Set up text cell
nameCell = [[customCell alloc] init];
[theTextColumn setDataCell:nameCell];

This is a memory leak. The column will take ownership of the cells, and you don't have any other references to them, so you need to release them after handing them over to the columns. Something like this:

[myColumn setDataCell: [[[MyCellClass alloc] init] autorelease]];

[cell representedObject];

What do you expect this call to do?

j o a r

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSTableView custom cell problem
      • From: j o a r <email@hidden>
References: 
 >NSTableView custom cell problem (From: Andrew Skinner <email@hidden>)
 >Re: NSTableView custom cell problem (From: j o a r <email@hidden>)

  • Prev by Date: Re: #ifdef/build style question
  • Next by Date: Re: NSTableView custom cell problem
  • Previous by thread: Re: NSTableView custom cell problem
  • Next by thread: Re: NSTableView custom cell problem
  • Index(es):
    • Date
    • Thread