如何在一個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 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");
}
}
這樣就可以記錄你的狀態了