I have a view-based NSTableView whose data is supplied by a subclass of NSArrayController. The array controller also receives NSNotifications (just 2) from other objects telling it to update. As long as the array controller is not acting as a delegate for the NSTableView, everything works as expected and each notification is received only once. When I attach the array controller as a delegate for the NSTableView (in IB), these same notifications are received multiple (like hundreds!) of times. The array controller is only registered once for these notifications (in awakeFromNib:).
2 Answers
Notifications and delegates are two independent mechanisms in Cocoa.
There must be something else going on in your code as attaching delegates shouldn't alter the number/kinds of notifications being received.

- 6,572
- 3
- 37
- 65
-
Thanks, Jay. That's what has me baffled. It is code that worked beautifully on a previous version, but is now broken. The only substantive change is from cell-based to view-based NSTableView. I'll keep digging. – Joel Mar 03 '14 at 08:34
For the sake of posterity.
In Apple's 'Table View Programming Guide for Mac' is this little nugget:
Note: Calling makeViewWithIdentifier:owner: causes awakeFromNib to be called multiple times in your app. This is because makeViewWithIdentifier:owner: loads a NIB with the passed-in owner, and the owner also receives an awakeFromNib call, even though it’s already awake.
So, when attached as a delegate, my class' awakeFromNib: was being called for every visible NSTableView cell, resulting in the notification observer being registered each time.

- 44
- 3