I have this code:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSDictionary *data = [list1 objectAtIndex:row];
NSNumber *strt = [data objectForKey:@"ab1"];
NSNumber *strt2 = [data objectForKey:@"ab1"];
forlb1 = [NSString stringWithFormat:@"%d", strt.intValue];
forlb2 = [NSString stringWithFormat:@"%d", strt2.intValue];
NSDictionary *xt = [list1 objectAtIndex:row];
NSString *name = [xt objectForKey:@"name"];
NSDictionary *xx = [list1 objectAtIndex:row];
NSString *name2 = [xx objectForKey:@"name"];
switch (component)
{
case 0:
show1 = name;
label1.text = forlb1;
break;
case 1:
show2 = name2;
label2.text = forlb2;
break;
}
}
- (IBAction)goView:(id)sender
{
if (label1.text < labe2.tex)
{
ViewController1 *first = [[ViewController1 alloc]init];
first.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:first animated:YES];
}
else
{
ViewController3 *third = [[ViewController3 alloc]init];
third.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:third animated:YES];
}
}
My problem is: I can’t get ViewController3 if my label1.text < label2.text
When I select from component 1 of Picker view, one of my labels show the Name, and Another, label1 show me a number, same thing happens with component 2 of Picker view, now is ok, but when I should touch the button, I need to go to viewcontroller 1 or viewcontroller 2, depends of: label1.text < label2.text
Help me please.
You should not be comparing
label.textusing the less then<operator. Depending on the content of the label, you should either convert the text to number and do a check, or compare strings alphabetically.This is how to compare strings numerically, assuming that the text represents an integer number:
This is how to compare strings alphabetically: