PDA

View Full Version : Disabling Buttons




MrC539
Nov 14, 2005, 11:28 PM
Hi everyone,

I'm fairly new to Obj-C/Cocoa, and I've been working on a simple app. One thing I would like to add is to make the default button to be disabled unless two textfields have something written in them. I've searched Google a bit, and it seems I need to use "bindings" but the sites don't explain how to use bindings very well. Could someone point me in the right direction on disabling the default button unless 2 text fields are filled?

Thanks.



caveman_uk
Nov 15, 2005, 03:25 AM
You don't necessarily need to use bindings as you can use NSButton's setEnabled: method.

Personally I'd set up my controller as a delegate of both the NSTextField's and catch the

- (void)controlTextDidChange:(NSNotification *)aNotification

delegate method. In this I'd check that both the NSTextFields have something in them and if they do setEnabled on the NSButton appropriately.

MrC539
Nov 15, 2005, 10:18 AM
Thanks :)