简体   繁体   中英

NSCell not properly displayed

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM