-2

如果 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"];

}
}

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

4

1 回答 1

2

您不能将字符串与<or进行比较>。这应该可以为您提供所需的内容:

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第一个。这是Apple 有关该方法的文档的链接,以获取更多信息。

于 2013-10-01T04:54:52.430 回答