0

私はココアを初めて使用し、私が書いているサンプルアプリで少し問題があります:

@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

理由は?

どうも

4

1 に答える 1

1

-deallocのメソッドを定義する必要がありますDeviceDetection

-(void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

編集1 -

DrivesOnDock[5207:707] -[DeviceDetection value]: unrecognized selector sent to instance 0x100475b40 when the app starts.

クラスで定義valueしていないため、上記のエラーが発生します。DeviceDetection

于 2012-05-17T17:55:00.490 に答える