3

Is there a way to check if the up or down button is pressed in NSStepper Action event?

In my ViewController.h I have this:

- (IBAction)myStepperAction:(id)sender;

In my ViewController.m I have this:

- (IBAction)myStepperAction:(id)sender { }

In my event handler I have the following: (I'm using C# but I can read some Swift)

    partial void myStepperAction(Foundation.NSObject sender) {
        var stepper = sender as NSStepper;
        //var upPressed = stepper.upButton==true ? true : false;

    }

Related question:

Is there a way to add the mouse event to an Action in Interface Builder?

Update:
Why not store the previous value and then compare? Well, I'm coming from other frameworks where information like this in the event:

event.previousValue; // store previous value
event.gestureDelta; // if -1 left swipe if 1 the right swipe
event.currentTarget == stepper.upButton // target or current target is the control in a composite component and there is a property reference to the up and down buttons 
1.21 gigawatts
  • 16,517
  • 32
  • 123
  • 231
  • 1
    Why not just look to see whether the value got larger or smaller? – matt May 26 '21 at 23:28
  • You need to store the current value to a class variable for comparison. – El Tomato May 27 '21 at 00:53
  • @matt - In some environments the event comes with more information. I've updated the post. if I can get any of those three items I can determine which button was pressed – 1.21 gigawatts May 27 '21 at 01:21
  • What is the framework ? Where does the three items come form ? – ColeX May 27 '21 at 02:08
  • If you are going to use Cocoa, you can’t expect it to work like some other random framework, and the standard Cocoa stepper is a single control. Your application would presumably be using the value of the stepper somewhere, and since you know what that value is, it is pretty easy to know if the new value is greater or less. – red_menace May 27 '21 at 02:27

0 Answers0