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 SelectionNotifyMatrix

In the last section you implemented an Info window for the application and set up the infrastructure to coordinate changes to the current ToDo item. Now you want the Info window to synchronize its displays when the user selects a new ToDo item in a ToDoDocument by clicking or tabbing into a field. In this section you’ll implement this functionality.

As you’ll recall from Chapter 12, the list of ToDo items displayed in a ToDoDocument’s window is an NSMatrix of text cells. To implement proper synchronization of the application’s Info window with the current ToDo item, you’ll create a subclass of NSMatrix that can detect changes in the current selection and post a notification for interested observers (e.g., the InfoWindowController).

This section provides a good example of how to override the behavior of an Application Kit class. You can often achieve the desired changes in object behavior by creating a subclass that adds only a small amount of code to its superclass. Such is the case with the subclass you’ll create now: SelectionNotifyMatrix.

Create Files for SelectionNotifyMatrix

In Project Builder, create the interface and implementation files for the new class and add them to the project. Add the following declarations to the header file:

#import <Cocoa/Cocoa.h>

extern NSString *RowSelectedNotification;

@interface SelectionNotifyMatrix : NSMatrix {
}
@end

Add the definition for the string to the implementation file:

@implementation SelectionNotifyMatrix ...

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