Boy, do I feel like a dummy.

While investigating when setObjectValue: is getting called on the cell, I set a 
breakpoint in my override of that method and decided to check the call stack to 
see who was calling it -- assuming that it was the text field itself in its 
implementation of textShouldEndEditing: as I had guessed previously. But when I 
looked, I saw the following stack:

[TestTextFieldCell setObjectValue:]
[NSCell setStringValue:]
[NSCell stringValue]
[MyViewController control:isValidObject:]
...

Turns out that rather than validating the object passed to me in 
control:isValidObject:, I was stupidly getting the stringValue directly from 
the text field and validating that -- and apparently asking for the stringValue 
causes the cell to retrieve the current edited text from the field editor and 
call setStringValue: on itself with that text before returning it.

I fixed my code to validate the object passed in isValidObject instead, and now 
the pending edit is not committed to the cell when I return NO -- 
setObjectValue: doesn't get called. As a result, if the user enters invalid 
text and presses tab/return/enter and then unchecks the checkbox, the text 
field reverts back to the previous valid value as desired.

Thanks to those who took time to pass along their thoughts. My apologies for 
boring the list with problems caused by my own buggy code :-P
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to