0

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 ]] ;
}
kAiN
  • 2,559
  • 1
  • 26
  • 54

2 Answers2

1

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]];
}
Cyrille
  • 25,014
  • 12
  • 67
  • 90
  • Cyrille Hello and thank you for your answer ... I initialized in viewDidLoad      FFVariabileNumerica_CFU_Votazione = 12; When I start the bill, starting directly from 12 to 30 but does not stop how can I set the lock? This is when I need to add value and when it subtracts ... How can 'solve? Thank you so much Rory – kAiN Oct 10 '13 at 15:22
  • Perfect Answer! this is Correct! Thanks Cyrille and Thanks ManicMonkOnMac!! Thanks for your Answer – kAiN Oct 10 '13 at 15:55
1

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++;

}

ManicMonkOnMac
  • 1,476
  • 13
  • 21