2 mapmapm MapMapM 于 2012.11.21 10:01 提问

iPhone-方法关联在一个if语句中

如何在一个if语句中检测一个方法是否运行?比如:

if ([(UIButton *)sender isEqual:blueButton] && **showBlueText method is running** )
{
    Keep playing.
}
else if ([(UIButton *)sender isEqual:blueButton] && **showBlueText method is NOT running** )
{
    Game over.
}

-(void)showBlueText
{
blueText.hidden = NO;
[self performSelector:@selector(hideText) withObject:nil afterDelay:textDelay];
[self performSelector:@selector(showGreenText) withObject:nil afterDelay:hideDelay];
}

说明一下,showBlueText自身的循环,想检测一下showBlueText现在是不是在运行

1个回答

Mr_me
Mr_me   2012.11.21 10:32
已采纳
// new iVar
BOOL textIsShowing;

// method
-(void)showBlueText {
  textIsShowing = YES;
  blueText.hidden = NO;
  [self performSelector:@selector(hideText) withObject:nil afterDelay:textDelay];
}

// method
- (void)hideText {
  textIsShowing = NO;
  blueText.hidden = YES;
}

// button press
- (void)buttonPressed {
  if (textIsShowing) {
    NSLog(@"Keep playing");
  } else {
    NSLog(@"Game over");
  }
}

这样就可以记录你的状态了

MapMapM
MapMapM 谢谢
5 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!