Create a Custom View to Display ToDoItem Status

For the To Do application, you’ll implement a three-state button to indicate a ToDoItem’s status. The button will show, with an image, three possible states: not done (no image), done (an X), and deferred (an O). These states correspond to the possible states of a ToDoItem.

The ToDoCell class, which you will implement in this section, generates cells that behave as three-state buttons. These buttons also display the time an item is due. Here’s how you add the cell images to the project:

  1. In Project Builder, create an Images group inside the Resources group.

  2. Choose Add Files from the Project menu.

  3. In the Add Images, select the file DoneMark.tiff.

  4. If you want to create a self-contained project, choose the option to copy the files into the project directory.

  5. Click OK.

  6. Repeat the same steps for file DeferredMark.tiff, which is in the same location.

  7. Now that you have an Images group, move LeftArrow.tiff and RightArrow.tiff into it.

Why Choose NSButtonCell as a Superclass?

The superclass of ToDoCell is NSButtonCell. In creating ToDoCell, you will add data and behavior to NSButtonCell and override some existing behavior. This choice prompts two questions:

  • Why a button cell and not the button itself?

  • Why this particular superclass?

NSCell defines state as an instance variable, so all cells inherit it. Cells, rather than controls, hold state information for reasons of efficiency—one control (a matrix) can manage a collection of cells, ...

Get Learning Cocoa 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.