O'Reilly logo

Cocoa Programming for OS X: The Big Nerd Ranch Guide by Aaron Hillegass, Adam Preble, Nate Chandler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required