我正在开发我的第一款iPhone游戏,想知道当第一个函数调用第二个函数时,如何从函数返回值?函数返回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;
}
当我直接调用第二个函数时没有问题,但当调用第一个函数时,它又调用第二函数,我如何正确地将第二个功能的值返回给第一个函数,以便它可以将其返回到调用的位置。
感谢
我不确定我能不能抓住你。只需退回:
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;
}
编辑
- (BOOL) inrect:(CGPoint)_point
{
return [self inrect:_point:0];
}