8.8. Working with Table Views
Tables are widely used in Mac OS X applications for displaying lists of information. You can see examples of it everywhere, from a list of messages displayed in Mail, to lists of files and build errors in Xcode. Table views often present information in multiple columns, with each column name appearing in the column's header. Columns and rows sometimes can be reordered within the table. AppKit supplies a single class that can be used in all of these situations: NSTableView.
The NSTableView class works with data in a different manner than other Cocoa controls. The controls you've seen so far, including text fields, text views, and image views, all use simple accessor methods to get and set the control's value. NSTableView does not store your list data itself; instead, it asks for your data on demand from another object, which NSTableView calls its data source. An NSTableView data source is an Objective-C object, perhaps simply an NSObject subclass that implements a special collection of methods, called a protocol. The NSTableView data source protocol specifies the methods used by the table view to get your object data. These are especially important when working with NSTableView objects directly, through Interface Builder outlets and actions.
You can also supply NSTableView data through Cocoa Bindings, using an NSArrayController to manage the list of your modal data. In this case, the table view will use the Key Value Coding mechanism to find your list ...
Get Beginning Mac OS® X Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.