我是 Cocoa 的新手,我在编写一个示例应用程序时遇到了一些问题:
@implementation DeviceDetection
- (id) init {
self = [super init];
if (self) {
notCenter = [[NSWorkspace sharedWorkspace] notificationCenter];
[notCenter addObserver:self
selector:@selector(discMounted:)
name:@"NSWorkspaceDidMountNotification"
object:[NSWorkspace sharedWorkspace]]; // Register for all notifications
}
return self;
}
- (void)discMounted:(NSNotification *)notification
{
NSLog(@"COUCOU");
}
@end
#import <Foundation/Foundation.h>
@interface DeviceDetection : NSObject {
NSNotificationCenter *notCenter;
}
- (void) discMounted:(NSNotification *)notification;
@end
@implementation AppDelegate
@synthesize window = _window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
DeviceDetection* d = [[DeviceDetection alloc] init];
[d value];
}
@end
使用那段代码插入 USB 驱动器时出现以下错误:
[NSRunLoop discMounted:]: unrecognized selector sent to instance 0x10054c5a0
有什么理由吗?
谢谢