我有一个类似“静态”的类,我希望能够响应低内存警告。但是,当我从模拟器手动触发低内存警告时,我收到“无法识别的选择器”错误。
相关代码:
@interface MyClass : NSObject
+ (void) receiveNotification:(NSNotification*) notification;
@end
@implementation MyClass
+ (void) initialize {
[super initialize];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveNotification) name:@"UIApplicationDidReceiveMemoryWarningNotification" object:nil];
}
+ (void) receiveNotification:(NSNotification*) notification {
// Breakpoint here never hits.
// I instead receive error "+[MyClass receiveNotification]: unrecognized selector sent to class".
}
@end
答案 0 :(得分:2)
您的方法名称为receiveNotification:
(请注意冒号是名称的一部分)
所以选择器应该是@selector(receiveNotification:)
我希望有所帮助。