如何传递手势选择器的参数 [英] how to pass argument for gesture selector

查看:99
本文介绍了如何传递手势选择器的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在标签上添加了一个手势,当点击时我想触发将int作为参数的showlbl,但是我收到编译器错误:

I added a gesture to a label and when tapped i would like to trigger showlbl that will take int as an argument, however I'm getting a compiler error for:

UITapGestureRecognizer *gestlbl0 = [[UITapGestureRecognizer alloc] initWithTarget:self 
                                                action:@selector(showlbl:1)   ];

谢谢!

推荐答案

它不起作用。您只能指定选择器的名称,即要调用的方法的名称。选择器的形式(参数的数量)是固定的,并由调用您的操作方法的类(在本例中为 UITapGestureRecognizer )定义。

It doesn't work that way. You can only specify the name of the selector, i.e. the name of the method that is to be called. The form of the selector (the number of arguments) is fixed and defined by the class that calls your action method (in this case, UITapGestureRecognizer).

对于此特定操作方法,action方法的唯一参数将是 UIGestureRecognizer * 类型的对象。如果您有方法可以访问另一个变量,则必须声明一个适当的ivar / property并将值存储在那里。

For this particular action method, the one and only argument to the action method will be an object of type UIGestureRecognizer *). If you the method to have access to another variable, you have to declare an appropriate ivar/property and store the value there.

这篇关于如何传递手势选择器的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆