-(IBAction)someMethod:(UIStepper *)sender{
int x=sender.value; //This is an integer from 0-8;
NSLog(@"%f",sender.value);
NSArray *rpmValues = [[NSArray alloc]initWithObjects:@"a",@"b",@"c",@"d",@"e",@"f",@"g",@"h",@"i", nil];
if (x<=[rpmValues count]) {
myLabel.text = [rpmValues objectAtIndex:x];
}
NSLog(@"%i",[rpmValues count]);
}
Above is my code, what I want to do is to change UILabel display by changing UIStepper. This is very straight forward. But when I change press the stepper value, it crashes:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** - [__NSArrayM objectAtIndex:]: index 1 beyond bounds for empty array'
*** First throw call stack:
And the [rpmValue count] is 9. I really got confused. Can anyone help me?
ifstatement needing to use<and not<=, this code looks OK. Are you 100% sure the error is coming from this code and not some other place?int xmanually to 1 seems to work for me, can you try this? Your NSLog statement is wrong, what doesNSLog(@"%d",sender.value);print? Something else must be causing the problem.