NSTextFieldCell "challenge"
NSTextFieldCell "challenge"
- Subject: NSTextFieldCell "challenge"
- From: "Geert B. Clemmensen" <email@hidden>
- Date: Fri, 17 Dec 2004 10:30:18 +0100
Hello,
I have a subclassed NSControl that among other things hold a NSTexFieldCell (textCell). When editing of the the cell, using the standard field editor, is ended, this textDidEndEditing: method gets invoked:
- (void) textDidEndEditing:(NSNotification*) notification
{
NSTextView* e = [notification object];
NSString* str = [NSString stringWithFormat:@"%@", [e string]];
[textCell setStringValue:str];
[textCell endEditing:e];
NSLog(@"New textCell=%@", [textCell stringValue]);
[e setString:@""];
NSLog(@"Done textCell=%@", [textCell stringValue]);
...
}
The spooky part, or at least so I believe, is the
[e setString:@""] call, i.e. the field editor contents is supposedly cleared, BUT the textCell's string value is ALSO cleared (actually it is set to the same value as the field editor is set to). Here is NSLog output (editing the text cell twice)
2004-12-17 08:49:00.295 XYZ[3447] New textCell=aaaaa
2004-12-17 08:49:00.295 XYZ[3447] Done textCell=
2004-12-17 08:49:16.598 XYZ[3447] New textCell=sssss
2004-12-17 08:49:16.599 XYZ[3447] Done textCell=
The
stringWithFormat: was a desparate attempt to make sure that I was working with a copied string, but it doesn't make difference, i.e.
NSString* str = [e string];
works as good (or bad :o).
I fail to see why setting the field editor, after its string has been copied and used when setting the text cell, also sets text cell. I have also tried to remove the field editor from its superview etc., but all to no avail.
Another interesting note is that [textCell stringValue] actually ends up invoking setStringValue:. I subclassed NSTextFieldCell, overwrote setStringValue: and gets this stack trace for
[textCell stringValue]:
#0 -[MyTextFieldCell setStringValue:] (self=0x59cc70, _cmd=0x9089684c, s=0x501fd0) at FTMUIText.m:19
#1 0x92e366b0 in -[NSActionCell stringValue] ()
#2 0x00016400 in -[XYZControl textDidEndEditing:] (self=0x59bf90, _cmd=0x9089b740, notification=0x59eb20) at XYZControl.m:380
I realize that there is probably something very obvious that I am missing, so if a kind soul "out there" has spotted my error, please tell me.
Regards,
Geert B. Clemmensen
www.frontbase.com
_______________________________________________
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