[英]pass a variable between two methods
I was trying to pass a variable of type NSString from a method to another. 我试图将NSString类型的变量从一个方法传递给另一个方法。 what I have done is:
我所做的是:
-(void)some{
NSString *lat = something
NSString *longt = somethingElse
[self test:lat:longt];
}
and then 接着
- (IBAction)test:(NSString *)lat:(NSString *)longt{
doSomeThing
}
But my problem is that now the IBAction button is activated without my press. 但是我的问题是,现在不按我就可以激活IBAction按钮。
how do I run the method IBAction under my control 如何在我的控制下运行IBAction方法
you cannot pass arbitrary parameters through an IBAction, you can either pass the control sending the action or nothing: 您不能通过IBAction传递任意参数,可以传递发送操作的控件,也可以不传递任何内容:
-(IBAction)action:(id)sender;
or
-(IBAction)action;
The test method should not be an IBAction
. 测试方法不应为
IBAction
。 Instead do this: 而是这样做:
- (void)test:(NSString *)lat:(NSString *)longt{
//doSomeThing
}
-(IBAction)myAction:(id)sender
{
//call test from here
[self some];
}
You should use void as returm type of method not ibaction. 您应该使用void作为方法的替代类型,而不是action。 If u need it for some action thn call it from there.
如果您需要它进行某些操作,则可以从那里调用它。
use 采用
- (void) test:(NSString *)lat:(NSString *)longt
instead of 代替
- (IBAction)test:(NSString *)lat:(NSString *)longt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.