I'm trying to display 256 cells in a NSCollectionView. I'm using Storyboard but the NSCollectionViewItem is in a separate xib. It is registered in the CollectionView at startup. A DataSource object holds an array (NSMutableArray) with numbers which are loaded into the representedObject of a NSCollectionViewItem when one is provided by the makeItemWithIdentifier(...) function.
func collectionView(collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int {
return dataArray.count
}
func collectionView(collectionView: NSCollectionView, itemForRepresentedObjectAtIndexPath indexPath: NSIndexPath) -> NSCollectionViewItem {
let item = collectionView.makeItemWithIdentifier("CellItem", forIndexPath: indexPath) as! CellCollectionViewItem
item.representedObject = dataArray[indexPath.indexAtPosition(1)]
item.index = indexPath.indexAtPosition(1)
item.dataSource = self
return item
}
When the cells should be displayed only (exactly) 100 cells are rendered instead of all 256. At no point does the data array hold 100 items. Furthermore, my debug output shows that actually all NSCollectionViewItems are produced. That means the problem must lie in the rendering of the collection view. Is there a restriction to the amount of items the NSCollectionView can render at once? What am I missing?
The remaining cells appear when the window is slowly resized by the user and disappear again if the user resizes the window fast. Does the view stop rendering after a fixed amount of time?