I want something similar to how iWork has a template selection screen for pages, when you can select different templates, and each view contains different information, has difference sizes, etc.
I tried to subclass NSCollectionView and determine which view to display using the newItemForRepresentedObject method (as opposed to using the itemPrototype Interface Builder), but for some reason does not position the views correctly and does not show the correct number of views for the number of items present. Here is my code. I was hoping someone might have a better way to do this, or an example of how this is done.
personView and companyView are properties in the NSCollectionView subclass that are IBOutlets to view in IB.
-(NSCollectionViewItem *)newItemForRepresentedObject:(id)object{ NSCollectionViewItem *collectionViewItem = [[NSCollectionViewItem alloc] init]; [collectionViewItem setRepresentedObject:object]; if([[object valueForKey:@"company"] boolValue] == YES){ NSView *view = [companyView retain]; [collectionViewItem setView:companyView]; }else{ [collectionViewItem setView:personalView]; } return collectionViewItem;
}
objective-c cocoa macos nscollectionview
Patrick
source share