如何传递变量到新方法我调用时使用@selector(methodname) [英] How to pass variable to new method I call when using @selector(methodname)

查看:252
本文介绍了如何传递变量到新方法我调用时使用@selector(methodname)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定非常快的问题。我使用MKMapAnnotation添加注释到我的iOS。我创建一个int和一个带有公开按钮的注释,它调用loadPano方法,例如:

Ok very quick question. I am adding annotations to my iOS using MKMapAnnotation. I create a int and an annotation with a disclosure button Which calls the method loadPano like so:

int integervariable;
[disclosureButton addTarget:self 
                     action:@selector(loadPano) 
           forControlEvents:UIControlEventTouchUpInside];    

现在说我想在方法中访问整数变量load pano我该怎么做我很难理解当我们像上面那样调用这个方法时,如何将变量传递给新的方法。

Now say I want to access the integer variable in the method load pano how would I do this, I am struggling to understand how I would pass the variable to the new method when it is called like the above.

推荐答案

必须传递与每个公开按钮关联的整数,您可以设置 disclosurebutton.tag =整数值;

If you just have to pass an integer associated to each disclosurebutton, you can set disclosurebutton.tag = integer value;.

同样为了这个工作,声明 loadpano 这样:

Also for this to work, declare loadpano this way:

- (void)loadPano:(UIButton*)sender
{
    NSInteger relevantInteger = sender.tag;
   // More code here
}

[disclosureButton addTarget:self 
                     action:@selector(loadPano:) 
           forControlEvents:UIControlEventTouchUpInside];    

请注意,此方法现在接受一个参数,因此选择器包含冒号。

Note that the method now takes a parameter so the selector includes a colon.

这篇关于如何传递变量到新方法我调用时使用@selector(methodname)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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