List of Views in Cocoa
What is the best GUI element that will work as a container for views? I will have number of views (say 50), all of them the same but I want to remove and add them at runtime. I'm looking for something like a table but w开发者_StackOverflowith single column and changable number or rows.
NSCollectionView
or (since OS X 10.7) NSTableView
are the appropriate classes for such a task. Simply bind them to an NSArrayController.
While NSCollectionView
requires all contained views to share the same dimensions, NSTableView
allows variable heights.
Oh, and last but not least there of course also is the 3rd party class PXListView
.
You might also want to check out this answer on a related question: custom list control in cocoa
As Regexident said, NSCollectionView
is Apple's way of doing what you're mentioning.
Alternatively, check out JUCollectionView
:
JUCollectionView aims to be a drop in replacement for the extremely slow NSCollectionView. Instead of loading every possible cell at once, JUCollectionView only displays the visible cells. To improve the performance even further, JUCollectionView also reuses cells where possible. This means that it only has to load a batch of cells to cover the view and then reuse them its whole lifetime.
精彩评论