Re: NSSlider value difference in two places...
Re: NSSlider value difference in two places...
- Subject: Re: NSSlider value difference in two places...
- From: Graham Cox <email@hidden>
- Date: Mon, 02 Jun 2014 11:37:44 +1000
I can't see anything obviously wrong Peter - assuming your text fields do update properly it would suggest that your sliders are connected, in which case the second bit of code should work. Whatever the problem is, it's not in this part of the code.
I would say that your approach here is a bit unorthodox, though it should work. Normally it's a good idea to declare separate actions for each control so they only have to do one job, and you don't need to use a tag to identify the control. Also, a better design would be for the action method to set the values in the data model, and for other related display, such as the text fields, be updated by a change to the data model (e.g. using KVO). That way, if some other code changes the data model, your UI is still correct. That said, for very simple interfaces, going out of your way to make it work "correctly" is often more work than seems worthwhile.
--Graham
On 2 Jun 2014, at 11:19 am, Peters, Brandon <email@hidden> wrote:
> Graham,
>
> For the first action:
>
> Declaration:
>
> // allows user to set the value of the friction coefficient
> IBOutlet NSSlider *_frictionSlider;
>
> // displays friction coefficient chosen by the user
> IBOutlet NSTextField *_frictionDisplay;
>
> // allows user to set the mass
> IBOutlet NSSlider *_massSlider;
>
> // displays the mass chosen by the user
> IBOutlet NSTextField *_massDisplay;
>
> // allows the user to set the amount of forces applied to the ball
> IBOutlet NSSlider *_forceAppliedSlider;
>
> // displays the amount of force the user wishes to apply
> IBOutlet NSTextField *_forceAppliedDisplay;
> }
>
> When the sliders are moved:
>
> -(IBAction)changeParameters:(id)sender
> {
> // user adjusts slider for mass
> if([sender tag] == RBS_MassSliderTag)
> {
> [_massDisplay setFloatValue:[_massSlider floatValue]];
> NSLog(@"Mass in changeParameters: %f\n", [_massSlider floatValue]);
> }
> // user adjusts slider for friction
> else if([sender tag] == RBS_FrictionSliderTag)
> {
> [_frictionDisplay setFloatValue:[_frictionSlider floatValue]];
> }
> // user adjusts slider for force applied
> else
> {
> [_forceAppliedDisplay setFloatValue:[_forceAppliedSlider floatValue]];
> }
> }
>
> When the start button is pressed:
>
> // friction
> [_simulationView setFrictionCoefficient:[_frictionSlider floatValue]];
>
> // mass
> NSLog(@"Mass in startSimulation: %f\n", [_massSlider floatValue]);
> [_simulationView setMass:[_massSlider floatValue]];
>
> On Jun 1, 2014, at 8:37 PM, Graham Cox <email@hidden> wrote:
>
>>
>> On 2 Jun 2014, at 10:28 am, Peters, Brandon <email@hidden> wrote:
>>
>>> have a slider used to adjust a value. When the slider is moved, an action is triggered to display the value in a panel. When a start button is pressed, another action is triggered, and within that action the value of the slider is ascertained. I have discovered than when calling the second action, the value of the slider is zero, unlike the value when called from the first action. Is this expected behavior? How can get the slider to retain its value from the first called action? Thanks.
>>
>>
>> This isn't the expected behaviour; sliders and all controls have a value that they remember constantly. How are you referring to the slider in the second action? Using an outlet? Is it connected?
>>
>> Show your code - something else is wrong.
>>
>> --Graham
>>
>>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden