当函数被另一个函数调用时如何返回? iPhone编程

发布于 2025-01-08 18:34:11 字数 846 浏览 0 评论 0原文

我正在开发我的第一个 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 bools.

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薔薇婲 2025-01-15 18:34:11

我不确定我是否能理解你。只需返回即可:

return [self inrect:_point:0];

I'm not sure I'm getting you. Just return it:

return [self inrect:_point:0];
長街聽風 2025-01-15 18:34:11

我不确定您的问题,但也许您想这样做:

- (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];
    }

I am not sure to understand your problem, but maybe you want to do this:

- (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;
    }

EDIT

- (BOOL) inrect:(CGPoint)_point
    {
        return [self inrect:_point:0];
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文