O'Reilly logo

Learning Cocoa by Apple Computer Inc

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required