Passing int from one Function to another
I really have no idea how this is done, it should be simple but i just cant get it
i have an IBAction and void and want to 开发者_JS百科do this:
-(IBAction)pass{
int VariableX = 10;
[self getVar]; ---> send var to -(void)getVar
}
-(void)getVar{
get the VariableX
if(VariableX=10){
do something
}
}
declare getVar function to get one (integer) parameter:
// header
-(void)getVar:(int)varX;
// implementation
-(void)getVar:(int)varX{
if (varX == 10)
// do something
}
Then call it the following way:
-(IBAction)pass{
int VariableX = 10;
[self getVar:VariableX];
}
Generally the syntax of method declaration in objective-c is:
- (ReturnType) functionName:(1st parameter type)1stParameterName
2ndParameter:(2nd parameter type)2ndParameterName
etc
精彩评论