Domanda

in my app I'm taking into account the clicks made ​​on a botton . The number of clicks is displayed in a label and I used this code ... I wish that the number of clicks started not from 0 but from 12 and stop automatically at 30. How can I give these blocks in my action where I draw the NSInterger ?

Thank you all for the help

@ interface FFDettagliEsami () {
    NSInteger FFVariabileNumerica_CFU_Votazione ;   
}

@ end

@ implementation FFDettagliEsami
   
- ( IBAction ) FFAddVotazione : (id ) sender {
    FFVariabileNumerica_CFU_Votazione + + ;
    [ FFVotazioneLabel setText : [ NSString stringWithFormat : @ " % d", FFVariabileNumerica_CFU_Votazione ]] ;
}
È stato utile?

Soluzione

You can initialize FFVariabileNumerica_CFU_Votazione to whichever value you want in places like viewDidLoad: or initWith... if it's a view controller.

And for stopping at 30, just add a check :

- (IBAction)FFAddVotazione:(id)sender {
    if (FFVariabileNumerica_CFU_Votazione >= 30)
        return;

    FFVariabileNumerica_CFU_Votazione++ ;
    [FFVotazioneLabel setText:[NSString stringWithFormat:@"%d", FFVariabileNumerica_CFU_Votazione]];
}

Altri suggerimenti

use

static NSInteger FFVariabileNumerica_CFU_Votazione = 12;

and in - ( IBAction ) FFAddVotazione : (id ) sender

add the condition to check for FFVariabileNumerica_CFU_Votazione < 30

if(FFVariabileNumerica_CFU_Votazione < 30){ FFVariabileNumerica_CFU_Votazione++;

}

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top