I currently use a UIStepper
in a custom UITableViewCell
hooked up to a UITextField
to have people select how many items they want to add to their Shopping Cart.
To check if the object is in stock, I've got two numbers: The LocalStock and the TotalStock.
I want to do the following:
If the amount of objects falls into the local stock, I want the textfield the number is displayed in to turn green.
If the amount of objects falls into the supplier stock (so either there is no local stock, or the stepper value is higher than the local stock, so we need to get it from the supplier stock) turn the UITextField
blue.
If neither the supplier stock nor local stock are sufficient, I want the textfield to turn yellow.
I got the following code:
- (IBAction)stepperValueChanged:(id)sender
NSLog(@"localstock: %@",localstock);
NSLog(@"TotalStock: %@",totalstock);
NSDecimalNumber *value = [NSDecimalNumber decimalNumberWithString: self.textField.text];
if (value <= localstock)
{
self.aantalTextField.backgroundColor = [UIColor greenColor];
NSLog(@"Value %@ <= Localstock %@ >GREEN< Totalstock: %@",value,localstock, totalstock);
}
else if (value <= totalstock)
{
self.aantalTextField.backgroundColor = [UIColor blueColor];
NSLog(@"Value %@ <= totalstock %@ >BLUE< Localstock: %@",value,totalstock,localstock);
}
else
{
self.aantalTextField.backgroundColor = [UIColor yellowColor];
NSLog(@"Value: %@ LocalStock: %@ TotalStock %@ >YELLOW<",value,localstock,totalstock);}}
And it's not making much sense when I run it... Sometimes it catches the GREEN-statement, other times the BLUE, and sometimes the same value returns YELLOW.
Anyone care to take a look at this and show me where the (logical) error is?
Thanks in advance!