当函数被另一个函数调用时如何返回? iPhone编程
我正在开发我的第一个 iPhone 游戏,并且想知道当第一个函数调用第二个函数时如何从函数返回值?该函数返回布尔值。
这是一些示例代码:
// 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;
}
当我直接调用第二个函数时没有问题,但是当调用第一个函数(它又调用第二个函数)时,如何正确地将第二个函数的值返回到第一个函数,以便它可以将其返回到调用它的位置。
谢谢
I am working on my first iPhone game and am wondering how to return a value from a function when this first function calls a second function? The functions returns bool
s.
Here is some sample code:
// 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
Here are functions:
- (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;
}
There is no problem when I call the second function directly, but when calling the first function, which in turns calls the second function, how do I properly return the value of the second function back to the first function so it can return it to where it was called from.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定我是否能理解你。只需返回即可:
I'm not sure I'm getting you. Just return it:
我不确定您的问题,但也许您想这样做:
编辑
I am not sure to understand your problem, but maybe you want to do this:
EDIT