Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 我想制作一个视图控件,它实际上是一个times table测试_Ios - Fatal编程技术网

Ios 我想制作一个视图控件,它实际上是一个times table测试

Ios 我想制作一个视图控件,它实际上是一个times table测试,ios,Ios,我试过制作一个iphone应用程序,它会显示两个随机数字,然后你输入答案,然后按submit,它会显示一个标签,上面写着正确或错误 但是当我编写代码时,它总是正确显示 代码如下: - (IBAction)but01Pressed:(id)sender{ NSLog(@"B111111"); RandomNum = arc4random() %25; if (RandomNum == 0) { RandomNum = arc4random() %25

我试过制作一个iphone应用程序,它会显示两个随机数字,然后你输入答案,然后按submit,它会显示一个标签,上面写着正确或错误 但是当我编写代码时,它总是正确显示 代码如下:

 - (IBAction)but01Pressed:(id)sender{

    NSLog(@"B111111");

    RandomNum = arc4random() %25;

    if (RandomNum == 0) {
        RandomNum = arc4random() %25;
        if (RandomNum == 0) {
            RandomNum = arc4random() %25;
        }
    }

    //@"GLOBAL=%@   %@",appd.globalString, name.text

    lab01.textColor = [UIColor blueColor];
    lab02.textColor = [UIColor blackColor];

    textF01.hidden = NO;
    textF02.hidden = NO;
    textF03.hidden = NO;
    adotime01.hidden = NO;
    equal01.hidden = NO;
    SubmitFQ01.hidden = NO;



    textF01.text = [NSString stringWithFormat:@"%d",RandomNum];

    RandomNum = arc4random() %15;

    if (RandomNum == 0) {
        RandomNum = arc4random() %15;
        if (RandomNum == 0) {
            RandomNum = arc4random() %15;
        }
    }

    textF02.text = [NSString stringWithFormat:@"%d",RandomNum];



}

 `enter code here`- (IBAction)submitbutPressed:(id)sender;
{
    if (textF03.text == [NSString stringWithFormat:@"%d",[textF01.text intValue] * [textF02.text intValue]]) {
        label066.text = @"Wrong";
        label066.hidden = NO;
    }
else
    {
        label066.text = @"Right";
        label066.hidden = NO;
    }

        }
这:

应为:

if ([textF03.text isEqualToString:[NSString stringWithFormat:@"%d",[textF01.text intValue] * [textF02.text intValue]]]) {
或者更好:

if ([textF03.text intValue] == [textF01.text intValue] * [textF02.text intValue]) {
您不能使用
==
比较两个对象值以查看对象是否表示相同的值

正如在评论中提到的,当
if
语句为真时,这就是“正确”答案,而不是“错误”答案

旁注:

为什么要使用此代码:

RandomNum = arc4random() %25;

if (RandomNum == 0) {
    RandomNum = arc4random() %25;
    if (RandomNum == 0) {
        RandomNum = arc4random() %25;
    }
}
我猜你实际上想要一个1-24范围内的随机数,对吗?如果是这样,只需执行以下操作:

randomNum = arc4random() % 24 + 1; // gives 1-24
更好的方法是使用:

randomNum = arc4random_uniform(24) + 1;

对其他值进行类似的更改。

看起来您在最后一个if语句中有与不正确的大小写相关联的
正确
错误
。您缺少并在
[textF03.text intValue
上结束paren。
randomNum = arc4random_uniform(24) + 1;