Re: NSWorkspace's notificationCenter
Re: NSWorkspace's notificationCenter
- Subject: Re: NSWorkspace's notificationCenter
- From: Dan Saul <email@hidden>
- Date: Mon, 14 Mar 2005 01:15:52 -0600
Try removing the class from all observances using -removeObserver:self.
On Mon, 14 Mar 2005 00:59:58 -0500, Joannou Ng <email@hidden> wrote:
> Hi folks,
>
> Imagine a simple app with two buttons: Add & Remove
>
> Add does the following:
> - (IBAction)add:(id)sender {
> [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self
> selector:@selector(deviceMounted:)
> name:@"NSWorkspaceDidMountNotification" object:[NSWorkspace
> sharedWorkspace]];
> }
>
> Remove does the following:
> - (IBAction)remove:(id)sender {
> [[[NSWorkspace sharedWorkspace] notificationCenter]
> removeObserver:self name:@"NSWorkspaceDidMountNotification"
> object:[NSWorkspace sharedWorkspace]];
> }
>
> Then, we have the observer method:
> - (void)deviceMounted:(NSNotification *)notification {
> NSLog(@"Great!");
> }
>
> Here's the issue:
> I click Add.
> I trigger the notification by mounting something.
> The observer method gets invoked.
> Great!
> I click Remove.
> I trigger the notification by mounting something again.
> The observer method does not get invoked.
> Great!
> I click Add.
> I trigger the notification by mounting something again.
> The observer method gets invoked TWICE!
>
> The invocations will increase as I repeat...
>
> Any ideas?
>
> Cheers, Joannou.
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden