objective-c – NSWorkspacedidmountNotify /可能是通用的NSWork
发布时间:2020-12-16 07:32:07 所属栏目:百科 来源:网络整理
导读:我是一名经验丰富的C/C++程序员,但却是ObjC的新成员.我正试图在Mac OSX项目中捕获NSWorkspacedidmountnofification. 我将回调添加到我的app delegate界面. - (void)mediaMounted:(NSNotification *)notification; 实施包括 - (void)mediaMounted:(NSNotifica
我是一名经验丰富的C/C++程序员,但却是ObjC的新成员.我正试图在Mac OSX项目中捕获NSWorkspacedidmountnofification.
我将回调添加到我的app delegate界面. - (void)mediaMounted:(NSNotification *)notification; 实施包括 - (void)mediaMounted:(NSNotification *)aNotification { NSLog(@"mediaMounted volume change."); } 在我的applicationDidFinishLaunching中,我将自己添加到通知中心. NSNotificationCenter* ncenter = [[NSWorkspace sharedWorkspace] notificationCenter]; [ncenter addObserver: self selector: @selector(mediaMounted) name: NSWorkspaceDidMountNotification object: nil]; 但是,当我运行并装载磁盘时,我看到: 2012-08-29 09:52:31.753 OSN[2203:903] -[OSNAppDelegate mediaMounted]: unrecognized selector sent to instance 0x101340af0 2012-08-29 09:52:31.756 OSN[2203:903] -[OSNAppDelegate mediaMounted]: unrecognized selector sent to instance 0x101340af0 我确认Instance 0x101340af0是我的OSNAppDelegate self,但我不明白我还需要做什么,以便识别选择器. 解决方法
你的选择器应该是:
mediaMounted:不是mediaMounted. 您的实现将NSNotification作为参数,而不是任何内容. 您可以通过以下方式验证选择 if( [self respondsToSelector:@selector(mediaMounted)] ) { NSLog(@"Good to go"); } 例: // this selector @selector(test) // will call this method - (void)test{ } // but this selector,noting the : @selector(test:) // would call this method - (void)test:(id)sender{ } 您可以阅读有关选择器here的信息. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |