objective c - Safely remove NSView that contains cocoa bindings -
i have inspector pane in app contains bunch of controls. these controls bound model objects through nsarraycontroller
. depending on type of object selected displaying different set of inspectors (just how ib works). inspector controller observes array controller's selection
, can load required set of inspectors when selection changes.
the problem old set of inspectors isn't removed apparently. through inspector controller doesn't hold strong reference them , removed superview, still stick around , log binding errors console:
[<circle 0x102107df0> valueforundefinedkey:]: class not key value coding-compliant key width.
my guess nsarraycontroller
holds strong reference controls because of bindings. possible? manually have remove binding before removing control superview? how implement inspector pane this?
edit: documentation says
neither receiver, nor anobserver, retained.
so guess bindings should removed automatically when removing control, shouldn't it?
the problem there isn't defined order between inspector controller's response selection
changing , various inspector views updating in response same thing. so, "wrong" inspectors new array controller selection still there brief time, @ least, , trying access non-existent properties of element objects.
one fix not rely on key-value observing array controller selection
switch set of inspectors in , out. rather, have coordinating controller – whichever controlling "selected object" based on user action – clear set of inspectors before changing selection , not switching in new set of inspectors until after has been changed.
Comments
Post a Comment