Hi Alastair, I already created a sub-class for NSFormatter to help control input. For instance, the ID value must be only numeric characters and up to 8 digits.
My current problem is the case where the user doesn't type anything and leaves the current cell. Regarding point 1: The ID numbers will correspond to an ID that's stored on a device, so on average, there is no use for a default value. But it is an alternative I was thinking about if I cannot get rid of my current issue. The value will be useless without a device with the corresponding ID, but at least it will be a legal entry. Regarding point 2: I was trying to prevent the table from entering a state where illegal entries exist. One requirement for the ID, is that they must be unique. Usability-wise, I figure that the user probably would like to know about an illegal entry as soon as they enter it, rather than being told about them later when they would like to save the list. As soon as the user starts typing, there's no problem. If they delete the entire cell and try to move on, the alert message will come up and send them back to the illegal cell. If they changed their minds about adding a new entry, the cancelOperation: method is overloaded to abort editing and deletes the current line. It's just trouble-some because of the difference in behavior: - Create new entry -> enter value -> delete value -> leave cell -> alert message pops up - Create new entry -> leave cell -> nothing (blank entry is added to the list) If all else fails, I suppose I can just omit the blank entries when saving. The other illegal entries will either be prevented by the formatter or the user will be forced to deal with at the time of entry. -Chris -----Original Message----- From: Alastair Houghton [mailto:alast...@alastairs-place.net] Sent: Tuesday, August 11, 2009 2:33 PM To: Chris Arnaiz Cc: cocoa-dev@lists.apple.com Subject: Re: Forcing a cell's field editor to send control:textShouldEndEditing: when leaving a cell On 11 Aug 2009, at 19:53, Chris Arnaiz wrote: > I've been struggling to control the behavior of a NSTableView while > editing cells. [snip] > My goal is to prevent the user from leaving a cell (mouse click, tab > key, enter key, etc) before they provide a valid value for that entry. Hi Chris, Rather than trying to use -control:textShouldEndEditing:, have you tried using an NSFormatter subclass? That's the way I would normally implement validation for user input, and it's possible that it *might* solve your problem. Also, two other points worth considering: 1. Can you fill in a reasonable default value? I'm sure you've thought about this already, but a very Mac-like thing to do is to go to considerable lengths to work out what to do by default, so that your user doesn't have to. 2. Is preventing the user from leaving the field really the best option? Might it be better to merely ignore empty entries, or even to remove them automatically at some point? Again, I'm sure you've considered this already, but it's an important point. Sometimes there are better options. Kind regards, Alastair. -- http://alastairs-place.net _______________________________________________ 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com