Objective c 如何在收到点击次数后显示警报视图

Objective c 如何在收到点击次数后显示警报视图,objective-c,ios,xcode,Objective C,Ios,Xcode,正如标题所暗示的那样,我正在努力弄清楚,在按钮被点击一定次数后,我如何显示警报。到目前为止,我想出了 - (IBAction)count:(id)sender { { UITouch *touch = [count]; if (touch.tapCount == 4) { } UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"My alert text here"

正如标题所暗示的那样,我正在努力弄清楚,在按钮被点击一定次数后,我如何显示警报。到目前为止,我想出了

- (IBAction)count:(id)sender {

{
    UITouch *touch = [count];
    if (touch.tapCount == 4)
    {
}
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"My alert text here" delegate:nil cancelButtonTitle: @"Ok" otherButtonTitles: nil];

[alert show];

 }

}

上面的方法不起作用,我把我的按钮
count
设置为动作和出口
counted
那代码没有什么意义(我很惊讶它能编译,是吗?)。当你选择一个按钮时,UITouch不是你的一部分。我认为您需要做的是记录按钮被按下的次数,并将其存储为实例变量

例如(在您的实现中):


在代码静态值开头的某处定义:

static int numberTouches;
并设置在某个位置(在视图中将显示):

numberTouches=0

比:


请记住,将0设置为您想要进行此操作的数字触控,例如在viewDidDissapear中,或者如果用户在其他地方录制,请将0设置为您的数字触控。

我个人不使用
静态int numberTouches,它更像是C语言的遗物,对于初学者来说,在这种上下文中使用static是令人困惑的(可能意味着它在类的所有实例中都是全局的,而实际上它只是意味着变量具有文件范围)。Obj-C方法更多地是通过使用属性和类扩展来实现的。No不会编译,只是表明id至少自己努力解决了这个问题。谢谢你的帮助,效果很好!对于可能需要此代码的任何其他人,只需将NSUinteger
m_按钮更改为TouchCount
即可。
static int numberTouches;
- (IBAction)count:(id)sender {
{
    numberTouches++;
    if(numberTouches == 4)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"My alert text here" delegate:nil cancelButtonTitle: @"Ok" otherButtonTitles: nil];
        [alert show];
    }
}