I have an custom NSCell in an NSTableView and it doesn't display correctly. The table view has the right number of items in it but they're empty except for the first one. The first one shows the cell but its values change randomly when I click somewhere on the NSTableView. I suspect this has something to do with my cell's copyWithZone:
. My cell doesn't have any iVars, just a drawWithFrame:inView:
method that draws its objectValue. In copyWithZone:
I return [[[MyCell allocWithZone: zone] init] autorelease]
Should I return something else?
You should not -autorelease
the result of -copyWithZone:
. "copy" is one of the three magic words in Cocoa (new, alloc and copy) that indicate that the returned object should have an effective +1 retain on it.
Also, note that you should always call the cell's designated initializer at some point (initImageCell:
or initTextCell:
). If your init
doesn't call one of those, then you're probably not initializing your cells correctly. See Subclassing NSCell.