Re: No Alert, Discard Change, & Beep
Re: No Alert, Discard Change, & Beep
- Subject: Re: No Alert, Discard Change, & Beep
- From: Quincey Morris <email@hidden>
- Date: Tue, 19 Apr 2016 22:52:38 -0700
- Feedback-id: 167118m:167118agrif8a:167118s_kxaSN6ez:SMTPCORP
On Apr 19, 2016, at 22:25 , Richard Charles <email@hidden> wrote:
>
> I am not sure where the alert sheet comes from but …
I just looked this up here:
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CocoaBindings/Concepts/MessageFlow.html <https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CocoaBindings/Concepts/MessageFlow.html>
under the heading "User Updates a Value in the User Interface”. This picture dates back to OS X 10.5, but it’s still accurate AFAIK — which is an indication of the last time bindings functionality was … er … improved, or even changed, really. According to this, the NSFormatter validation happens very early. (If you ever feel you’ve grasped OS X, this is a good page to prove you wrong. ;) )
One alternative solution is to use a “captive” NSFormatter. That is, take it off the text field in IB, and create one in code. Then implement the KVC validate<Key> method to apply the formatter yourself, and deal with the formatting failure however you want.
To do this, you could create a KVO-compliant derived NSString property in (say) your view or window controller, and bind the naked text field to that instead.
It’s more work than you’ve done (and you have to figure out the quirky validate<Key> API) but it gives you more control about what you do when the input is invalid, and what you change the invalid field back to. I mention this because beeping is only a marginally less crappy UI than the one you’re trying to avoid.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden