views:

32

answers:

2

user can only listen to three songs before he/she has to login or else they won't be able to listen anymore. for that can I compare IBAction like that (if(IBAction < 3)he stop and he have login for more song. This same question as I Ask before I am trying to solve that give me hint to do.

thanks in advance

A: 

You should introduce a member of type int. Initialize it with 0. Each time your play action is called, check if it has reached your threshold. If yes, display the login screen, otherwise increase it by 1.

tob
+1  A: 

IBAction is simply a marker for interface builder so that it knows what methods to provide connections for. If you look at in UINibDecleartions.h you will find

#ifndef IBAction 
#define IBAction void
#endif

So no, you can do anything in code with IBAction. What you are looking for is probably something like

//Header
@interface SomeController : UIViewController {

    NSInteger numTimesPressedButton;
} 
-(IBAction)doSomething:(id)sender;

....

//.m File

- (id)initWithNibName:(NSString *)aNibName bundle:(NSBundle *)aNibBundle{

    self = [super initWithNibName:aNibName bundle:aNibBundle];
    if(self != nil)
    {   
        numTimesPressedButton = 0;
        ...
    }
    return self;
}

-(IBAction)doSomething:(id)sender{

    numTimesPressedButton++;
    if (numTimesPressed > 3)
        [someThing doSomeThingElse];
    ...
}
Ben
thank youit working but the when the numTimesPressed count increased 4 it stop it didn't go to next song Ok.But problem is that if i want to listen the pervious 3 song it doesn't allow me . help me sir
You are going to have to redefine your data model. You don't want to be looking at the number of times a user has pressed a button, but rather how many songs are loaded. I would suggest you create an NSArray, when a user wants to load another song, check to see the count of the array before loading the song reference into the array. Only allow the user to listen to songs with references from the array.
Ben