newbie question: How to count the no of times a method has been accessed?

Discussion in 'iOS Programming' started by kingthong, Oct 7, 2010.

  1. kingthong macrumors member

    Joined:
    Sep 20, 2010
    Location:
    Somewhere but not here.
    #1
    Hi,

    i have a method

    -(IBAction) score: (id) sender{}

    It is accessed by pressing down a button on the Iphone. i want it to run only 5 times. how do i achieve that?

    Thanks.
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    I'd set up a counter and then only execute the code inside your method if the counter is <= 5. (Don't forget to increment the counter each time, as well.)
     
  3. Luke Redpath macrumors 6502a

    Joined:
    Nov 9, 2007
    Location:
    Colchester, UK
    #3
    Create an integer instance variable in your controller to track the number of times it is called, increment in the action method and check the count as a guard clause?
     
  4. kingthong thread starter macrumors member

    Joined:
    Sep 20, 2010
    Location:
    Somewhere but not here.

Share This Page