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

标签 objective-c ios xcode static-methods

.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

#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

当我打电话时:

[Reminders setRemindersForPerson: p];

这总是很好用。当我打电话时:

[Reminders setEightDayReminder];

我得到:

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

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

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

最佳答案

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

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

@interface SomeClass (MyCategory) ...

并且喜欢:

@interface SomeClass ...

关于objective-c - 发送到类的无法识别的选择器 - 对于没有参数的静态方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13602982/

相关文章:

objective-c - 缺少标识符 UIStoryboardPlaceholder 的代理

ios - 在同一个应用程序中从右到左和从左到右的语言?

ios - UISwitch 不改变状态

objective-c - NSView 和动态加载 subview

objective-c - 属性(property)拒绝综合

iOS:存储在安全区域中的 key 不支持解密

ios - objective-c - block 保留周期

ios - 选择时关闭 UIPopover

iphone - 在以编程方式获取的 MKMapView 屏幕截图中未捕获叠加层

xcode - 使用未解析的标识符 'FIRDatabase'