Challenge: Disabling the Send Button

As it stands, the Send button never gets disabled. But it should: when there is no message text entered, no action is taken when the user clicks the button. Disable the button at the appropriate time using bindings. In particular, bind the button’s Enabled value to File's Owner’s message property.

Of course, enabled needs a boolean and message is a string. To solve this problem, create a subclass IsNotEmptyTransformer of NSValueTransformer which will transform a string into a boolean.

You will want the button’s state to be updated as the user is typing. To accomplish this, open the text field’s Value binding in Interface Builder and check the Continuously Updates Value option. This will ensure ...

Get Cocoa Programming for OS X: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.