I feel this being a simple task, but I don't seem to be able to make it work. I'm trying to have a NSCollectionView with custom items. I added another NSImageView to the custom view of the item, and I subclassed this view in order to add the custom outlet connected to this additional NSImageView.
Now I am overriding - (NSCollectionViewItem *)newItemForRepresentedObject:(id)object
because sometimes I need to remove this NSImageView.
- (NSCollectionViewItem *)newItemForRepresentedObject:(id)object {
CustomItem *theItem = (CustomItem *)[super newItemForRepresentedObject: object];
...
if (I need to remove that NSImageView) {
[[theItem additionalImageView] removeFromSuperview];
}
return theItem;
}
Anyway, additionalImageView seems to be (nil)
. This is someway obvious because the super method will return the default NSCollectionViewItem which has not the custom outlet.
What's the best thing to do right here? I read something about the copy
method, and I tried with:
- (NSCollectionViewItem *)newItemForRepresentedObject:(id)object {
CustomItem *theItem = [(CustomItem *)[super itemPrototype] copy]; // Here is the change
...
if (I need to remove that NSImageView) {
[[theItem additionalImageView] removeFromSuperview];
}
return theItem;
}
But this is not going to work. So, is there a way to preserve custom outlets when using a custom NSCollectionViewItem?
Any help would be very appreciated. Thank you!