An optimized list view control for Mac OS X 10.5 and greater. It was created after I wrote this post on the subject.
PXListView is licensed under the New BSD license.
PXListView uses similar optimizations as
UITableView for the iPhone, by enqueuing and dequeuing
NSViews which are used to display rows, in order to keep a low memory footprint when there are a large number of rows in the list, yet still allowing each row to be represented by an
NSView, which is easier than dealing with cells.
The project is still very much a work in progress, and as such no documentation exists at current.
Each row in the list view is displayed using an instance of
PXListViewCell (which is a subclass of
NSView). The delegate of
PXListView responds to three messages in order for the control to function:
PXListView only keeps the bare minimum of list view cells in the view hierarchy to be performant, and when rows are scrolled onscreen new cells are added to the view hierarchy to display the rows, and when the rows are scrolled offscreen the associated cells are removed from the view hierarchy.
When responding to
-listView:cellForRow:, the delegate should first call
-dequeueCellWithReusableIdentifier: on the list view, passing in the reusable cell identifier, to see if there are any reusable cells available. If this returns
nil then a new cell can be created using the initializer
initWithReusableIdentifier: (declared on PXListViewCell). this keeps the memory footprint of the control as low as possible by reusing cells that have been scrolled offscreen, removed from the view hierarchy and cached.
PXListViewCell is an abstract superclass, implementing the bare minimum for such features as cell selection and declaring methods relied on by the list view.
You should create a concrete subclass of
PXListViewCell when using it in the list view, where
drawRect: can be overridden to do custom drawing, and properties used to store data for the cell can be declared on this subclass. The example project (as part of the repository) shows this.
Thanks to Mike Abdullah for optimizations related to cell dequeuing.
Thanks to Uli Kusterer for additions and fixes to PXListView including momentum scrolling, keyboard navigation, changes to variable row heights (using CGFloats), accessibility as well as drag and drop support.
Thanks to Tom for fixing a memory issue with reloading data.