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:
In Project Builder, create an Images group inside the Resources group.
Choose Add Files from the Project menu.
In the Add Images, select the file
DoneMark.tiff
.If you want to create a self-contained project, choose the option to copy the files into the project directory.
Click OK.
Repeat the same steps for file
DeferredMark.tiff
, which is in the same location.Now that you have an Images group, move
LeftArrow.tiff
andRightArrow.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.