且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么此NSInvocation引发异常?

更新时间:2023-11-20 21:55:34

糟糕.我跳了枪. Xcode的代码完成使我认为methodSignatureForSelector:NSMethodSignature的类方法.每当我处理类的时候,我通常不会经常打乱我,通常我会先输入[NSClassImUnfamiliarWith,然后输入一个空格.这样做会弹出Xcode的代码完成弹出窗口,该弹出窗口通常具有一个可以调用的所有方法.我不小心从NSObject中选择了一个继承(?)方法,以为这是一个类方法.我想这将是多态的一个例子.无论如何,我通过用对象tabViewItem.view替换NSMethodSignature解决了我的问题.因此,所有这些看起来像这样:

Oops. I jumped the gun. Xcode's code completion had me thinking that methodSignatureForSelector: was a class method of NSMethodSignature. Whenever I'm dealing with classes I don't usually mess with on a regular basis, I generally start by typing [NSClassImUnfamiliarWith, followed by a space. Doing so brings up Xcode's code completion popup, which generally has all of the methods one can call. I accidentally chose an inherited (?) method from NSObject thinking it was a class method. I guess this would be an example of polymorphism. Anyway, I solved my issue by replacing NSMethodSignature with my object: tabViewItem.view. So all together it looks like this:

NSMethodSignature *methodSig = [tabViewItem.view methodSignatureForSelector:@selector(setAlphaValue:)];

我不知道这是否对其他人有帮助,但是,天哪,我将其发布以防万一.祝你好运!

I don't know if this will help anyone else, but by golly, I'm gonna post this just in case. Good luck!