• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Unregistering KVO observers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unregistering KVO observers


  • Subject: Re: Unregistering KVO observers
  • From: Steve Nicholson <email@hidden>
  • Date: Thu, 17 Apr 2008 22:05:23 -0700

On Apr 17, 2008, at 9:01 PM, Hal Mueller wrote:

Look at Malcolm Crawford's Graphics Bindings example, which contains among other things two methods on GraphicsView to start and stop observation when an object of that class is created or destroyed.
http://homepage.mac.com/mmalc/CocoaExamples/controllers.html

That looks like he's unbinding observers that he set up in code. All of my bindings are set up in Interface Builder.

I use -removeObserver:forKeyPath: for each of the keypath notifications I have requested, and then I count on the superclass's dealloc method to take care of its own keypath notifications.

The problem is that I haven't programmatically requested any keypath notifications so my object doesn't know who its observers are or what the key paths are. I can manually keep track of the observers if I make them all IBOutlets and connect them in Interface Builder, but I still don't know what the key paths are. And making them all IBOutlets and keeping track of them seems to defeat the purpose of bindings.


You can also use -removeObserver: but that seems like a blunt instrument to me, especially since I don't know what the superclass is counting on.

I need something more like "removeObserved" since I'm trying to stop my object from being observed by others. It's too bad I can't do anything with the pointer returned by the observationInfo method. I can see in gdb that it has all the information I need, but I can't get at it.

It would help to see your dealloc and close methods, especially if you think you're having trouble with a notification that you didn't register for.

I don't have a close method and my dealloc just calls the accessor methods to deallocate my collection classes:


- (void)dealloc
{
    [self setZoneSelector:nil];
    [self setDumpSelector:nil];
    [self setPpfArrayTypes:nil];
    [self setIgorUnitConversions:nil];
    [super dealloc];
}

sample accessor:
- (void)setZoneSelector:(NSString *)newZoneSelector
{
    [_zoneSelector release];
    _zoneSelector = [newZoneSelector mutableCopy];
}

I must be missing a basic concept because this all seems opposite of what I'm expecting. This isn't an object that is observing others. It's being observed _by_ others and I want to break that connection. When my app was simply an NSDocument, it worked fine: when the window closed, the bindings were automatically broken. But now that I'm using NSDocument and NSWindowController, they aren't.

I should also mention that I'm using Tiger.

Thanks for the help,
-Steve
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Unregistering KVO observers
      • From: Hal Mueller <email@hidden>
References: 
 >Unregistering KVO observers (From: Steve Nicholson <email@hidden>)
 >Re: Unregistering KVO observers (From: Hal Mueller <email@hidden>)

  • Prev by Date: Re: Why is [nil aMessage] a no-op?
  • Next by Date: Re: @dynamic and Programmatic Access to Setters
  • Previous by thread: Re: Unregistering KVO observers
  • Next by thread: Re: Unregistering KVO observers
  • Index(es):
    • Date
    • Thread