Question

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:).

Was it helpful?

Solution 2

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top