I have an NSCollectionView
specified as both my DataSource and my Delegate.
I have two issues:
Rather than doing the
registerClass
method, attempting to instead use the 3 lines of commented code with the (non-nil) protoNib means of registering with anNSCollectionView
causestheItem
to always be nil.Using the class registry option, all works mostly fine. But if I remove the
willDisplayItem
anddidEndDisplayingItem
stubs, the system eats up gobs of memory on its first call toitemForRepresentedObjectAtIndexPath
(with thousands of internal calls to these two stubs) and eventually crashes. Instruments shows thousands of 4k@autoreleasepool content items
being created byAppKit
.
Any idea why this might be happening?
-(void)awakeFromNib {
[self registerClass:[MECollectionViewItem class] forItemWithIdentifier:@"EntityItem"];
// NSString *nibName = NSStringFromClass([MECollectionViewItem class]);
// NSNib *protoNib = [[NSNib alloc] initWithNibNamed:nibName bundle:nil];
// [self registerNib:protoNib forItemWithIdentifier:@"EntityItem"];
__weak typeof(self) weakSelf = self;
[self setDelegate:weakSelf];
[self setDataSource:weakSelf];
...
}
- (MECollectionViewItem *)collectionView:(NSCollectionView *)collectionView
itemForRepresentedObjectAtIndexPath:(NSIndexPath *)indexPath;
{
MECollectionViewItem *theItem = [self makeItemWithIdentifier:@"EntityItem"
forIndexPath:indexPath];
return theItem;
}
-(void)collectionView:(NSCollectionView *)collectionView
willDisplayItem:(NSCollectionViewItem *)item
forRepresentedObjectAtIndexPath:(NSIndexPath *)indexPath
{
}
-(void)collectionView:(NSCollectionView *)collectionView
didEndDisplayingItem:(nonnull NSCollectionViewItem *)item
forRepresentedObjectAtIndexPath:(nonnull NSIndexPath *)indexPath
{
}