newbie - confused by copyWthZone
newbie - confused by copyWthZone
- Subject: newbie - confused by copyWthZone
- From: Denis Stanton <email@hidden>
- Date: Tue, 2 Mar 2004 14:27:46 +1300
Hi
I have received some very helpful answers to questions in the last two
days. At the risk of wearing out my welcome I would like to ask
another.
I'm having trouble understanding what is required to have my class
understand "copyWithZone"
I'm trying to draw a small diagram ( a bit like a bar graph) in each
cell of one column of a tableView.
I have written a dataSource delegate
tableView:objectForTableColumn:row: to return a custom object.
I have subclassed NSTextFieldCell. I want it to receive this object
and use values in it to construct the drawing.
My problem is in my override of the drawInteriorWithFrame:inView:
method in my NSTextFieldCell subclass
If the object passed is an NSArray it's happy.
I can write
NSArray *array = [self objectValue]
and then I can use the values in the array.
Unfortunately I don't want to pass just the array, I want an instance
of my custom object Hires, which contains an NSArray and some other
instance methods.
if I write:
Hires *hires = [self objectValue];
I get a run time error "*** - [Hires copyWithZone:]: selector not
recognized"
Now my class Hires inherits from NSObject, and NSObject implements
copyWithZone, so why isn't that good enough?
In fact if I look up NSObject's copy with zone it says "You should not
override this method" which suggests to my inexperienced eye that
NSObject's copyWithZone will be good enough for my Hires object.
There is a warning in the definition of NSCell's objectvalue method
that may be relevant, but unfortunately I don't understand what it is
telling me.
It says:
objectValue
- (id <NSCopying>)objectValue
Returns the receiver's value as an Objective-C object if a valid object
has been associated with the receiver; otherwise, returns nil. To be
valid, the receiver must have a formatter capable of converting the
object to and from its textual representation.
I don't know how to add a formatter to my class. I'm not sure if this
omission is what is upsetting the copy with Zone request.
Denis
_______________________________________________
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.