views:

51

answers:

2

Ok, so I have an NSTextField and an NSSlider. In interface builder, I got the float value from the NSSlider to go into the NSTextField. BUT, I need a button that sends the text from the text field in so I can get the value in my code. That text field can also accept manual input so I cannot just link the NSSlider to my code. This is similar to pressing enter or when editing is finished. But I just need a button that sends all that data in when I click it.

Any ideas??

Elijah

+2  A: 

Follow Cocoa's MVC design.

Your text field and slider should take the values they present from some model object, and when the user manipulates them should push the new value to that model object.

You should not be using an NSTextField as an "intermediary" between another NSControl and a model object.

Chris Hanson
What should I use instead?
Elijah W.
The intermediary between Model and View objects is a Controller object. As for how to implement one in Cocoa, there are many examples that show exactly this.
Chris Hanson
A: 

The button is optional. You can link the TextField's "Value Changed" event to a function, then updates the Slider's value with the TextField's value.

ohho
Please note that the original poster is asking about Cocoa (NSTextField) not Cocoa Touch. Furthermore, controls typically only send actions due to user manipulation, not programmatic change, so the value would not propagate from the NSSlider to the NSTextField to other code.
Chris Hanson