从另一个函数调用函数时如何返回?iPhone编程
我正在开发我的第一款iPhone游戏,我想知道当第一个函数调用第二个函数时,如何从函数返回值?函数返回从另一个函数调用函数时如何返回?iPhone编程,iphone,objective-c,ios,cocoa-touch,ios-simulator,Iphone,Objective C,Ios,Cocoa Touch,Ios Simulator,我正在开发我的第一款iPhone游戏,我想知道当第一个函数调用第二个函数时,如何从函数返回值?函数返回bools 以下是一些示例代码: // This is sample calls to inrect functions: [menuButton inrect:point] // Calls the first function which calls second function [menuButton inrect:point:0.5] // No problem because cal
bool
s
以下是一些示例代码:
// This is sample calls to inrect functions:
[menuButton inrect:point] // Calls the first function which calls second function
[menuButton inrect:point:0.5] // No problem because calls the second function directly
以下是功能:
- (BOOL) inrect:(CGPoint)_point{
[self inrect:_point:0]; //call second function with offset of 0
return 0; //How do I return the value of the above call?
}
- (BOOL) inrect:(CGPoint)_point:(float)offset{
if (_point > 0 && offset > 1) {
return YES;
}
if (_point < 0 && offset < 1) {
return YES;
}
return NO;
}
-(BOOL)inrect:(CGPoint)\u点{
[self-inrect:_-point:0];//调用偏移量为0的第二个函数
return 0;//如何返回上述调用的值?
}
-(BOOL)inrect:(CGPoint)\ u点:(float)偏移{
如果(_点>0&&offset>1){
返回YES;
}
如果(_点<0&&offset<1){
返回YES;
}
返回否;
}
当我直接调用第二个函数时没有问题,但是当调用第一个函数时,它反过来调用第二个函数,我如何正确地将第二个函数的值返回给第一个函数,以便它可以返回到调用它的位置
谢谢我不确定能不能找到你。把它还给我:
return [self inrect:_point:0];
我不确定是否理解您的问题,但也许您想这样做:
- (BOOL) inrect:(CGPoint)_point
{
BOOL aBool = [self inrect:_point:0]; //put the return in a BOOL and do what you want with it
NSLog(@"Not expecting to this, but I do!");
return 0;
}
编辑
我猜你的意思是
返回aBool代码>是的,这就是我需要的!现在很明显。谢谢
- (BOOL) inrect:(CGPoint)_point
{
return [self inrect:_point:0];
}