在我的测验中使用标签问题

时间:2014-08-14 15:48:03

标签: objective-c

我是Xcode和Objective C的新手,对于古怪的代码感到抱歉。我试图让我的测验使用标签从一组8个问题中获得1-4的数字,最大分数是32,如果用户得分在0-8之间将它们带到这个故事板,那么 - 但是我在获取标签时遇到问题,并且在按下下一个按钮时检查当前数字是否小于或等于得分。

感谢您的帮助。

,H档

       IBOutlet UIScrollView *scroller;
    int currentNumber;
    int currentOperation;
    int score;

}

    - (IBAction)buttonDigitPressed:(id)sender;
    - (IBAction)next:(id)sender;

.M文件

- (IBAction)buttonDigitPressed:(id)sender{

    currentNumber = currentNumber *10 + (int)[sender tag];
    currentNumber = score;
}


- (IBAction)next:(id)sender {

       score = 36;
    if(currentNumber ==0 )score = currentNumber;
    else{

               score = score + currentNumber;

        }


    if (score <= 8){

            tool1ViewController *NVC = [self.storyboard instantiateViewControllerWithIdentifier:@"0-8"];
    [self presentViewController:NVC animated:YES completion:nil];

    }else if(score <=16){

            tool1ViewController *NVC = [self.storyboard instantiateViewControllerWithIdentifier:@“8-16”];
    [self presentViewController:NVC animated:YES completion:nil];

    }else if(score <=24){

            tool1ViewController *NVC = [self.storyboard instantiateViewControllerWithIdentifier:@“16-24”];
    [self presentViewController:NVC animated:YES completion:nil];


    }else if(score <=32){
    tool1ViewController *NVC = [self.storyboard instantiateViewControllerWithIdentifier:@“24-32”];
    [self presentViewController:NVC animated:YES completion:nil];


    }
}

1 个答案:

答案 0 :(得分:0)

使用CGFloat而不是int:

currentNumber = currentNumber *10 + (CGFloat)[sender tag];

 CGFloat currentNumber;

比较使用时:

if(currentNumber < 0.1 )

因为如果等于某个东西,则不应检查浮动值。

CGFloat被定义为32位浮点数和64位双倍,但如果你一直使用它,你不必考虑它。