问题
I have these two classes:
@interface Father : NSObject
{
NSString* name;
NSArray* listChildren;
}
@property (copy, readwrite) NSString* name;
@property (copy, readwrite) NSArray* listChildren;
@end
@interface Child : NSObject
{
NSString* nameChild;
NSImage* picture;
}
@property (copy, readwrite) NSString* nameChild;
@property (copy, readwrite) NSImage* picture;
@end
I'm trying to make a NSCollectionView
filled with Father
items, and for each father item's View
i will have a name label, and another NSCollectionView
filled with the (father) representedObject.listChildren
items.
I've managed to create an external NIB file for the father NSCollectionViewItem
's View
to make things easier, but I'm not able to bind the child CollectionView
to the representedObject.listChildren
property. Actually, there is no problem in binding in IB, and at runtime the system is actually calling the property (I've added and getListChildren
implementation and a NSLog call to make sure the property is being called). It seems that the inner CollectionView
's won't load the items found in my NSArray
* property?
It is driving me crazy, any ideas about what is going on? Help please!!
回答1:
I had the exact same problem and I found the solution!
I'm a complete novice to Objective C and Cocoa so I don't fully understand the reasons why this does not work exactly. Maybe somebody else can enlighten us.
In my first try I simply did everything in the default MainMenu.xib
. You end up with two NSArrayController
this way. Now apparently, as you suspected, the issue lies with the second NSArrayController
for the inner items. It somehow doesn't get "copied" correctly. Extracting each NSView
into its own .xib
solves this issue.
Actually this discussion got me started in the right direction. I later discovered/understood that this is the basically the same idea @user493638 already hinted at.
Combining this knowledge with the tutorial here, on how to extract the views into their own .xib
solved the problem for me!
Again I don't understand Objective C and Cocoa nearly enough to fully appreciate the underlying reasons for this behavior, who knows how exactly all this binding magic works under the hood...
来源:https://stackoverflow.com/questions/3533953/nscollectionview-inside-another-nscollectionview