how to pass argument for gesture selector

穿精又带淫゛_ 提交于 2019-12-20 06:28:49

问题


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)   ];

thanks!


回答1:


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).

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.



来源:https://stackoverflow.com/questions/11053884/how-to-pass-argument-for-gesture-selector

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!