2014-12-06 62 views
-1

这是一个愚蠢的简单的动画,但我不断得到这个恼人的“表达结果未使用”的警告。代码如下:恼人的“表达结果未使用”警告

-(IBAction)thingOneTapped:(UIGestureRecognizer *)sender{ 
    if ((isLevel = YES)) { 
     thingOneEnded = YES; 
     goingToThingOne = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(otherThingToOne) userInfo:nil repeats:YES]; 
     x = 11; 
     y = 118; 
    } 
    else (isLevel = NO); { 
     [self viewDidLoad]; 
    } 
} 

-(void)otherThingToOne{ 
    if ((isLevel = YES) && (isLevelOne = YES)) { 

     if ((x > 0) && (y > 0)) { 
     otherThing.center = CGPointMake(otherThing.center.x - .5, otherThing.center.y - 5.35); 
      x = x - .5; 
      y = y - 5.35; 
     } 
     else ((x < 0) && (y < 0)); { 
      [self levelOneDefault]; 
     // EVIL WARNING IS RIGHT HERE IN THE ELSE PART 
     } 
    } 
+2

为了检查平等,你需要使用==(即两个等号),这就是为什么你得到错误。此外,您的代码目前无法按预期工作。 – Fogmeister 2014-12-06 23:51:47

+0

总是简单的事情哈哈感谢 – PICKme 2014-12-06 23:52:20

+0

摆脱'else'行末尾的分号。 – rmaddy 2014-12-06 23:57:22

回答

0

为了检查平等,你需要使用==(即两个等号),这就是为什么你得到错误。此外,您的代码目前无法按预期工作。

正如别人所说。

而不是使用if(someBool == YES)只是使用if(someBool)。而不是if(someBool == NO)只是使用if(!someBool)

它不会在目前工作的原因是因为(我想,但不是100%在此)if(someBool = NO)将首先设置someBool为NO,然后评估,这将永远是if(NO)这将永远不会进入该块的状态。

我想。但由于我没有测试过,所以不确定。

+2

你不应该'if(someBool == YES)'。只要做'if(someBool)'。 – rmaddy 2014-12-06 23:58:50

+0

和'if(!someBool)'而不是'== NO'。 – Sulthan 2014-12-07 00:02:16

+0

为什么它现在不按预期顺序运行? – PICKme 2014-12-07 00:12:16

0

您也可以使用这样的不检查==运营商,也将是更多更快: -

if ((isLevel) && (isLevelOne)) 
相关问题