xcode 无法识别的选择器发送到类 - 对于没有参数的静态方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13602982/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 02:12:23  来源:igfitidea点击:

unrecognized selector sent to class - for static method with no parameters

objective-ciosxcodestatic-methods

提问by lewis

.h

。H

#import <Foundation/Foundation.h>
#import "Person.h"

extern NSString *const kRemindersWeekly;
extern NSString *const kRemindersDaily;

@interface Reminders : NSObject

+(void)setRemindersForPerson: (Person*) person;
+(void)setEightDayReminder;

@end

.m

.m

#import "Reminders.h"
@implementation Reminders

NSString *const kRemindersWeekly    = @"WEEKLY";
NSString *const kRemindersDaily     = @"DAILY";

+ (void) setRemindersForPerson: (Person*) person
{
    // some code
}

+(void)setEightDayReminder
{
    // some more code
}


@end

when I call:

当我打电话时:

[Reminders setRemindersForPerson: p];

this always works fine. When I call:

这总是工作正常。当我打电话时:

[Reminders setEightDayReminder];

I get:

我得到:

+[Reminders setEightDayReminder]: unrecognized selector sent to class 0xe1b58

Also, [Reminders setRemindersForPerson:];calls [Person setEightDayReminder]without any problems. Builds fine and Command clicking on functions in XCode shows it.I think everything is in order as it takes me to the appropriate places.

此外,[Reminders setRemindersForPerson:];通话[Person setEightDayReminder]没有任何问题。构建良好,命令单击 XCode 中的函数会显示它。我认为一切都井井有条,因为它会将我带到适当的位置。

Must be missing something obvious?! Pulling my hair out.

一定是遗漏了一些明显的东西?!拉我的头发。

回答by Lukas Kalinski

I had a very similar problem, and the cause was that I had a category in which I forgot to specify the category in the @implementation block, effectively overriding original implementation with the "new" one.

我有一个非常相似的问题,原因是我有一个类别,我忘记在 @implementation 块中指定类别,有效地用“新”实现覆盖原始实现。

Thus, if you have a category MyCategory on class SomeClass, make sure that its implementation looks like:

因此,如果您在类 SomeClass 上有一个类别 MyCategory,请确保其实现如下所示:

@interface SomeClass (MyCategory) ...

and notlike:

不是这样的:

@interface SomeClass ...

回答by Sulthan

There is one simple way to debug it - put a breakpoint there and watch what's happening.

有一种简单的调试方法 - 在那里放置一个断点并观察发生了什么。

See Creating breakpoint in Xcode for unrecognized selectorhow to create a breakpoint for unrecognized selectors. Your stack trace should tell you everything you need to know.

请参阅在 Xcode 中为无法识别的选择器创建断点如何为无法识别的选择器创建断点。您的堆栈跟踪应该告诉您您需要知道的一切。

Probably you should add your calling code as well.

可能你也应该添加你的调用代码。