Pregunta

En mi aplicación tengo una ibactación y dentro de ella tengo 2 instrucciones diferentes con un "si"

 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

El problema es que si presiono repetidamente el botón de esta ibactación, no funciona bien porque la Ibaction anterior no terminó su set de instrucciones1

Ejemplo = Presione el botón, ejecuta el conjunto de instrucciones 1, si presiono en otro botón, el botón no debería funcionar porque no termina su trabajo y quiero esperar el final de la instrucción establecida 1 para repetir el botón Push del botón.

¿Lo entiendes?

¿Fue útil?

Solución

Suponiendo que tienes BOOL workInProgress variable en tu clase:

- (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
        }
    }
}

Otros consejos

Use un valor de bool, configúrelo en el comienzo de su conjunto de instrucciones y vuelva a sí después. Si el valor es no, no haga nada

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top