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

}
}

しかし、1回目は完全に機能し、2回目はピエロが存在するかどうか(34または他の値であるかどうか)、アニメーション機能の代わりにその単一の画像のみを表示します。そのシミュレーターを実行するたびに、ifステートメントではなくelse部分のみが機能します。

4

1 に答える 1

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最初ではないことを確認してください。詳細については、メソッドに関するAppleのドキュメントへのリンクを次に示します。

于 2013-10-01T04:54:52.430 に答える