比较iphone中的动作

比较iphone中的动作,iphone,objective-c,Iphone,Objective C,用户在登录之前只能听三首歌,否则他们将无法再听。为此,我可以这样比较IBAction(如果(IBAction

用户在登录之前只能听三首歌,否则他们将无法再听。为此,我可以这样比较IBAction(如果(IBAction<3)他停止了,并且他登录了更多的歌曲。这个问题和我在试图解决这个问题之前问的一样,给我提示去做


提前感谢

您应该引入一个类型为
int
的成员。使用0初始化它。每次调用游戏操作时,检查它是否达到阈值。如果是,则显示登录屏幕,否则将其增加1。

您应该引入一个类型为
int
的成员。使用0初始化它。每次您的pla调用y操作时,检查它是否已达到阈值。如果是,则显示登录屏幕,否则将其增加1。

iAction只是interface builder的一个标记,以便它知道为哪些方法提供连接。如果查看uinibdeclearnations.h,您将发现

#ifndef IBAction 
#define IBAction void
#endif
所以不,你可以用iAction在代码中做任何事情

//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];
    ...
}

iAction只是interface builder的一个标记,它知道为哪些方法提供连接

#ifndef IBAction 
#define IBAction void
#endif
所以不,你可以用iAction在代码中做任何事情

//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];
    ...
}

谢谢你,它正在工作,但当numTimesPressed计数增加4时,它停止,它没有转到下一首歌。好的。但问题是,如果我想听前3首歌,它不允许我。请帮助我,先生,你将不得不重新定义你的数据模型。你不想查看用户按下按钮的次数,而是如何查看加载了许多歌曲。我建议您创建一个NSArray,当用户想要加载另一首歌曲时,请在将歌曲引用加载到数组中之前检查数组的计数。仅允许用户收听带有数组引用的歌曲。谢谢,它正在工作,但当numTimesPressed计数增加4时,它没有停止转到下一首歌好的。但问题是,如果我想听前3首歌,它不允许我听。请帮助我,您必须重新定义数据模型。您不想查看用户按下按钮的次数,而是查看加载了多少首歌。我建议您在用户要加载歌曲时创建一个NSArray另一首歌曲,请在将歌曲引用加载到数组之前检查数组的计数。仅允许用户收听包含来自数组引用的歌曲。