I am writing a Cocoa application that contains an NSTextField control. Things are such that when a user types a value into this control and hits enter, a binding will update an NSController instance in the application with the value contained in the text field.

This is more elegant that having to rely on creating an IBOutlet in the controller class and establishing a connection between the outlet and an action in the text field control to accomplish the same thing.

However, the application also contains a button that when clicked is also supposed to provide the controller with the contents of the text field. Obviously this could be done be create the appropriate outlets and actions and connecting them up in Interface Builder. However, this kind of defeats the whole purpose of using the binding mentioned earlier. It would be desirable to avoid creating outlets and actions for the button functionality as well.

Perhaps something could be done using the argument and action bindings in the button to affect the desired result. It is not obvious this could accomplished.

One thing I found was that if I implemented an action in my controller and connected it to the button, the controller could then call the commitEditing method in response to that action. This could accomplish the same thing as pressing enter in the text field control.

This only works though when the text field has been edited. If the text had not been edited, the user could still expect the button to cause the update. It would not be clear to them why the button wouldn't do anything when no editing had taken place.

One thought I had to make this relationship clear was to disable the button initially and then enable it only after the text field had been edited. I found I could do this by using the objectDidBeginEditing: method. By responding to that method I could use a binding that would affect the enabled state of the button.

In spite of this, what I also find is it that after implementing the objectDidBeginEditing: method, the action for the button that calls commitEditing no longer works. For some reason the control thinks that no editors need to commit any editing. If I remove the implementation for objectDidBeginEditing: things work fine. When I add it back in, things fail.

What can help me to implement the functionality I'm trying to develop?
_______________________________________________

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 [EMAIL PROTECTED]

Reply via email to