2013-10-11 56 views
0

我有五個(1美元硬幣)作爲按鈕是單擊oneButton函數發生,即硬幣將移動到框並顯示resultText.text爲1,第二個硬幣將...。高達五個硬幣。如何設置文本字段的最大值

如果resultText.text等於或大於eggamt,即(eggamt = 3),我將在eggDanceAnimation函數下面播放動畫。

這裏我懷疑是這兩個功能可以正常使用

  1. eggamt是3,如果條件發生。
  2. 卵子> 3其他條件發生。

問題是,我將四個硬幣移動到了框中resultText.text是顯示4並且播放動畫的實際需求是resultText.text是顯示3並播放動畫。

-(void)eggDanceAnimation { 
if (counter == 0 && [resultText.text isEqualToString:eggamt]){ 

    NSLog(@"%i", counter); 
    [self hideObjectAnimationDidStart]; 

    NSArray *dashBoy; 
    dashBoy = [[NSArray alloc] initWithObjects: 
      [UIImage imageNamed:@"a10001.png"], [UIImage imageNamed:@"a10002.png"], [UIImage imageNamed:@"a10003.png"], nil]; 
    stgImage1.animationImages = dashBoy; 
    stgImage1.animationDuration = 1; 
    [stgImage1 startAnimating]; 
} 

else if(counter==0 && [resultText.text compare:eggamt options:NSNumericSearch range:range]==NSOrderedDescending) { 
    stgImage1.image = [UIImage imageNamed:@"eggDanceHide.png"]; 
    stgText1.text= @"Oops! That is too much money, lets try again."; 

    oneBtn1.hidden = YES;oneBtn2.hidden = YES;oneBtn3.hidden = YES;oneBtn4.hidden = YES;oneBtn5.hidden = YES; 
    tenBtn1.hidden = YES;tenBtn2.hidden = YES;tenBtn3.hidden = YES;tenBtn4.hidden = YES;tenBtn5.hidden = YES; 
    fiveBtn1.hidden = YES;fiveBtn2.hidden = YES;fiveBtn3.hidden = YES; 
    fiveBtn4.hidden = YES;fiveBtn5.hidden = YES; 
    twentyFiveBtn1.hidden = YES;twentyFiveBtn2.hidden = YES;twentyFiveBtn3.hidden = YES; 
    twentyFiveBtn4.hidden = YES;twentyFiveBtn5.hidden = YES; 
    amtText.hidden = YES; 

} 
} 

- (void)oneButton:(UIButton*)oneBtn { 

CGRect frame = oneBtn.frame; 
CGRect frame1 = reffButton.frame; 
frame.origin.x = frame1.origin.x; 
frame.origin.y = frame1.origin.y; 

[UIView beginAnimations:nil context:nil]; 

[UIView setAnimationDuration: 3.0]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; 
[UIView animateWithDuration:3.0 animations:^{ 
    [oneBtn setTransform:CGAffineTransformMakeScale(.4, .4)]; 


} completion:^(BOOL finished) { 
    oneBtn.hidden = YES; 
     price = [resultText.text intValue]; 
     NSString *result=[NSString stringWithFormat:@"%i", price+1]; 
     [resultText setText:result]; 

     [[NSUserDefaults standardUserDefaults] setValue:result forKey:@"key"]; 
     [[NSUserDefaults standardUserDefaults] synchronize]; 


     [self eggDanceAnimation]; 

}]; 
oneBtn.frame = frame; 
[UIView commitAnimations]; 

} 

回答

1

您應該波紋管測試的東西:

-(void)eggDanceAnimation { 
int resultInt = [result.text intValue]; 
int eggInt = [eggamt intValue]; 
NSLog(@"Result is %d ; Eggamt is %d",resultInt,eggInt); 

那麼你比較,你想用什麼INT(這比使用的NSString更好),如

​​
相關問題