Note: Delegates vs notifications quirk -- {addObserver,setDelegate} != {setDelegate,addObserver}
Note: Delegates vs notifications quirk -- {addObserver,setDelegate} != {setDelegate,addObserver}
- Subject: Note: Delegates vs notifications quirk -- {addObserver,setDelegate} != {setDelegate,addObserver}
- From: Kirk Kerekes <email@hidden>
- Date: Fri, 27 Sep 2002 12:18:58 -0500
I post this in case it might save someone some hair-pulling.
I recently managed to (temporarily) break my application by moving a
delegate-setting operation from runtime code to the NIB. This "broke"
the app because "for historical reasons" (thank you, Apple, for that
wonderful circumlocution), I was using both the delegate and
notification versions of NSTextView's NSTextDidChange in the same
NSDocument object (for different functions). I have now changed this.
When I hooked the NSDocument up as the delegate of the NSTextView in
IB, the NSDocument stopped getting the notification, and just got the
delegate message.
In the code, I was calling addObserver for the notification before
setting the NSTextView delegate.
By setting the delegate in IB, I effectively changed the order of the
two calls, and this resulted in entirely different behavior.
While this is a reasonable optimization, the fact that it appears to be
call-order-sensitive is not particularly reasonable or intuitive. It
ought to work the same way regardless of call-order.
I have not done exhaustive testing on this. I do know that there is
nothing magical about setting the delegate in IB -- just changing the
call order in code accomplishes the same result, even if setDelegate:
is called _both_ before _and_ after addObserver:.
I do not know if this is a general mechanism, or if it only applies to
NSTextView.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.