Integrate NSStepper with NSTextField

I would have a model with one integer variable, which represents the value of both controls.

In my controller, I would use one IBAction, connected to both controls, and two IBOutlets, one for each control. then I would have a method for updating outlets from model value.

IBOutlet NSStepper * stepper;
IBOutlet NSTextField * textField;

- (IBAction) controlDidChange: (id) sender
{
    [model setValue:[sender integerValue]];
    [self updateControls];
}

- (void) updateControls
{
    [stepper setIntegerValue:[model value]];
    [textField setIntegerValue:[model value]];
}

This is the principle. As said by Peter Hosey, a formatter may be useful on your text field, at least to take min and max values of stepper into account.


Skip the takeIntValueFrom: method. Instead, bind both views to the same property in your controller. You may also want to create a formatter and hook up the text field's formatter outlet to it.


I found easy way is to bind stepper value to input and input value to stepper

@property (strong) IBOutlet NSTextField *timeInput;
@property (strong) IBOutlet NSStepper *timeStepper;

bind input value

bind stepper value