IOS: IBAction with two actions
Pergunta
In my app I have an ibaction and inside it I have 2 different instruction with an "if"
if (i == 0) //do instruction set 1
if (i == 1) //do instruction set 2
// and everytime I push button i change from 0 to 1 or from 1 to 0
the problem is that if I repeatedly press the button of this IbAction it don't work fine because the previous ibaction didn't finish its instruction set1
example = press button, it execute instruction set 1, if I push another time the button it shouldn't work because it it didn't finish its work and I want to wait the end of instruction set 1 to repeat the push of button.
Do you understand?
Solução
Assuming you have BOOL workInProgress
variable in your class:
- (IBAction)action {
if (!workInProgress) {
workInProgress = YES;
if (i == 0) {
// do something that in the end sets workInProgress to NO
} else if (i == 1) {
// do something else that in the end sets workInProgress to NO
}
}
}
Outras dicas
use a bool value,set it to NO at the begining of your instruction set,and back to YES after.if the value is NO then don't do anythig
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow