0

In my view, I have two steppers that are both linked to this function

- (IBAction)stepperChanged:(UIStepper *)sender {
    int value = [sender value];

    printf("value: %d", value);
}

Is there a quick and easy way to identify which stepper triggered this event?

Stupid.Fat.Cat
  • 10,755
  • 23
  • 83
  • 144

2 Answers2

3

Give the stepper a tag and then check the value of the tag. You can set a tag in code or in IB.

nsdebug
  • 364
  • 2
  • 8
1

You can also declare a property as well, which I like more than tags myself:

@property (nonatomic, strong) UIStepper *stepper1;

- (IBAction)stepperChanged:(UIStepper *)sender 
{
    if (sender == self.stepper1)
    {
        NSLog(@"Value of stepper1 is: %d",sender.value);
    }
}
klcjr89
  • 5,862
  • 10
  • 58
  • 91
  • You probably want to declare the property as IBOutlet UIStepper *stepper1 so that you can assign it from your storyboard/NIB in IB – Paulw11 Mar 17 '14 at 22:31
  • Maybe, but I don't use IBOutlets, so the code above is for my use case. Plus he didn't specify if it was for storyboard or not. – klcjr89 Mar 17 '14 at 22:57