问题描述
- 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
现在是不是在运行
解决方案
// new iVarBOOL 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""); }}
这样就可以记录你的状态了
时间: 2024-10-30 00:17:46