1

我有这个代码:

- (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];
    }
}

我的问题是:如果我的 label1.text < label2.text 我无法获得 ViewController3

当我从 Picker 视图的组件 1 中选择时,我的一个标签显示名称,另一个标签显示一个数字,同样的事情发生在 Picker 视图的组件 2 上,现在没问题,但是当我应该触摸按钮时,我需要去viewcontroller 1或viewcontroller 2,取决于:label1.text < label2.text

请帮帮我。

4

1 回答 1

0

您不应该label.text使用 less then<运算符进行比较。根据标签的内容,您应该将文本转换为数字并进行检查,或者按字母顺序比较字符串。

这是如何以数字方式比较字符串,假设文本表示一个整数:

if ([label1.text intValue] < [labe2.text intValue]) {
    ....
}

这是按字母顺序比较字符串的方法:

if ([label1.text compare:labe2.text] ==  NSOrderedAscending) {
    ....
}
于 2012-08-17T17:50:54.390 回答