如何在iOS中使用大于或小于

时间:2013-10-01 04:49:13

标签: ios objective-c

如果resultText等于clownamt(@“34”),我想显示动画,如果resultText不是clownamt的值,那么单个图像。这是我的要求。

-(void)clownDanceAnimation {
if (counter == 1 && [resultText.text isEqualToString:clownamt]){
    [self hideObjectAnimationDidStart];

    NSArray *dashBoy1;
    dashBoy1 = [[NSArray alloc] initWithObjects:
                [UIImage imageNamed:@"a20001.png"],[UIImage imageNamed:@"a20002.png"],
                [UIImage imageNamed:@"a20003.png"],[UIImage imageNamed:@"a20004.png"], nil];
    stgImage1.animationImages = dashBoy1;
    stgImage1.animationDuration = 1;
    [stgImage1 startAnimating];

}
else if((counter==1 && resultText.text > clownamt)) {
    stgImage1.image = [UIImage imageNamed:@"clownDanceHide.png"];

}
}

但第一次是完美的工作,第二次无论clownamt存在(无论是34还是其他值),它只显示单个图像而不是动画功能。每次我将运行该模拟器只能使用part而不是if语句。

1 个答案:

答案 0 :(得分:2)

您无法将字符串与<>进行比较。这应该可以帮到你找到你想要的东西:

NSString *string1;
NSString *string2;
if ([string1 compare:string2 options:NSNumericSearch] == NSOrderedDescending) {
    // numeric value of string1 > numeric value of string2
} else if ([string1 compare:string2 options:NSNumericSearch] == NSOrderedAscending) {
    // numeric value of string1 < numeric value of string2
} else {
    // numeric value of string1 == numeric value of string2
}

首先确保两个字符串都不是nil。以下是link to Apple's documentation on the method了解更多信息。

相关问题