是什么导致“错过的方法”在这段代码? [英] What causes "Missed Method" in this code?

查看:126
本文介绍了是什么导致“错过的方法”在这段代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果这是一个完全偏离标记的问题,或者如果我没有包含足够的信息,我会提前道歉 - 我对iOS开发(和Objective-C)很新,并且有跳跃的习惯深入了解...

Apologies ahead of time if this is a completely off-the-mark question, or if I'm not including enough information - I'm very new to iOS development (and Objective-C), and have a habit of jumping into the deep end...

我无法理解GameCenterManager.m中的callDelegate代码,该代码位于GKTapper示例代码中,并在此tuts + tutorial中提供: http:// mobile .tutsplus.com / tutorials / iphone / ios-sdk-game-center-achievement-and-leaderboards-part-2 /

I'm having trouble understanding the "callDelegate" code in GameCenterManager.m that's in the GKTapper Sample Code and also provided in this tuts+ tutorial: http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-game-center-achievements-and-leaderboards-part-2/

这是代码:

- (void) callDelegate: (SEL) selector withArg: (id) arg error: (NSError*) err
{
    assert([NSThread isMainThread]);
    if([delegate respondsToSelector: selector])
    {
        if(arg != NULL)
        {
            [delegate performSelector: selector withObject: arg withObject: err];
        }
        else
        {
            [delegate performSelector: selector withObject: err];
        }
    }
    else
    {
        NSLog(@"Missed Method");
    }
}

我的应用程序始终记录Missed Method行,但我不确定这个callDelegate代码实际上在做什么(所以我无法解决它)。我认为最好的方法是了解它实际上在做什么,并获得比错过的方法更好的输出...

My app always logs that "Missed Method" line, but I'm not sure what this callDelegate code is actually doing (so I can't fix it). I figure the best way forward is to learn what this is actually doing, and get better output than 'Missed Method'...

有一点需要注意,我的应用程序目前是在沙盒模式下使用Game Center,因为我还在开发它。在这种情况下可能会出现这种错过的方法行 - 我也不确定。

One caveat is that my app is currently using Game Center in sandbox mode, since I'm still developing it. This 'Missed Method' line might be expected in this situation - I'm not sure of that, either.

是否有人能够将此代码翻译成段落形式?我特别不确定'[delegate respondsToSelector:selector]'。

Would anybody be able to translate this code into paragraph form? I'm particularly unsure about the '[delegate respondsToSelector: selector]' piece.

或者,任何人都可以重写NSLog行,以便输出更多/相关的关于这个问题的细节?我试过这个,希望看到哪个选择器没有正确地通过'respondsToSelector',但它似乎不起作用:

Alternatively, would anybody be able to rewrite the NSLog line so that it outputs more/relevant detail about the problem? I tried this in the hopes of seeing which selector is not going through 'respondsToSelector' properly, but it didn't seem to work:

NSLog(@"Missed Method, %@", selector);


推荐答案

这是查看具体情况的最佳方式在callDelegate的开头放置一个断点,然后调试你的程序,而不是简单地运行它。您可以通过按cmd-y进行调试。

T'he best way to see exactly what is happening is putting a breakpoint at the beginning of callDelegate and then debugging your program, instead of simply running it. You can debug by pressing cmd-y.

这样做,每次程序进入callDelegate函数时,它都会停止并弹出调试器窗口。在那里你可以检查来电的来源和参数是什么。

Doing like this, each time your program enters the callDelegate function, it stops and the debugger window pops up. There you will be able to inspect where the call came from and what the parameters are.

至于这个函数的简单描述,我会说它是一个辅助函数通过在选择器存在之前检查它来包装对选择器的调用。您可以调用辅助函数来代替每次执行和执行选择器,它将为您执行这两项操作。

As to a plain description of this function I would say that it is an helper function that wraps a call to a selector by preceding it with a check of existence of that selector. Instead of checking each time and the performing the selector, you call the helper function that will do both things for you.

因此,您始终看到日志行的原因是您要调用的功能不在那里。通过使用调试器,您将能够看到它是哪个函数,哪个类缺少它,以及谁尝试了这个操作。

So, the reason you always see the log line is that the function you would like to call is not there. By using the debugger you will be able to see which function it is, which class is missing it, and who attempted the operation.

这篇关于是什么导致“错过的方法”在这段代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆