views:

90

answers:

1

I'm not really sure how to start debugging this issue.

I've got an NSCollectionView, whose NSCollectionViewItem prototype view itself contains an NSCollectionView (as well as an NSArrayController, to provide content to this 2nd-level collection view). Both levels of collection view work fine when the top-level view is in the main nib.

However, when I copy/paste the view (and reconnect all the appropriate bindings) to a new nib, which I load with loadNibNamed:owner:, the 2nd-level view--but not the top-level one--appears blank.

Upon some investigation, I discovered that myArrayController.arrangedObjects.@count is indeed 0. HOWEVER, the NSArray the controller is bound to (File's Owner's representedObject.quizzes), when asked for .@count, returns 2.

quizzes should indeed return 2, for I've done [testCategoryA setQuizzes:[NSArray arrayWithObjects:testQuizA1,testQuizA2,nil]];. I've tested setting the quizzes before the nibs are loaded and after. The situation is the same in both cases.

So, in conclusion, I've got 2 levels of collection views, with 2 levels of array controllers. The top level always works. But the 2nd level breaks whenever the top level isn't in the main nib file. And it seems to me that the part about the 2nd level that breaks is the binding of the array controller.

I don't even know how to start debugging in this tangled mess of nibs. Suggestions?

+1  A: 

It sounds as though your quizzes array is either not sending KVO notifications or you're editing it in a non-KVO-compliant way (ie, "editing the array behind the controller's back").

Further, you might want to check into Indexed Accessor Methods for your quizzes array for performance reasons.

Joshua Nozzi
I don't understand how `[testCategoryA setQuizzes:[NSArray arrayWithObjects:testQuizA1,testQuizA2,nil]];` could be non-KVO-compliant. Is there more to consider here than a properly-named accessor?
andyvn22
Joshua Nozzi: No, that is wrong. Accessors give KVO notifications for free unless you explicitly tell KVO not to. (One exception is, IIRC, CALayers.) This is detailed in the Key-Value Observing documentation: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/KeyValueObserving/Concepts/AutoVsManual.html
Peter Hosey
It appears you are correct. Thanks for pointing that out.
Joshua Nozzi