开发者

pass a variable between two methods

I was trying to pass a variable of type NSString from a method to another. what I have done is:

-(void)some{
NSString *lat = something
NSString *longt = somethingElse
开发者_Go百科[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.

how do I run the method IBAction under my control


you cannot pass arbitrary parameters through an IBAction, you can either pass the control sending the action or nothing:

-(IBAction)action:(id)sender;
or
-(IBAction)action;


The test method should not be an 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. 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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜