Copyright ã1996 by NeXT Software, Inc.  All Rights Reserved.

;UpdatingAClassDefinition.rtfd;;¬  Next Section	;ImplementingASubclassOfNSView.rtfd;;¬  Previous Section

Addingexistingclassestoyournibfile;¬Adding existing classes to your nib file 

¬	Drag the header file from the File Viewer or Project Builder into the nib file window.

Or

¬	Copy a class in one nib file and paste it in another.

The easiest way to add a class to your nib file is to drag the header file for an existing custom class from the Workspace Manager's File Viewer or from Project Builder's main window into Interface Builder.

¬

The new class appears in the Classes display under its subclass and with its outlets and actions defined. After adding the class, you must still connect it to other objects through its outlets and actions. To do this, complete these steps:

¬	Make an instance of the class (for NSView subclasses, that means assigning your class to a view object).

¬	Connect the instance's outlets and actions to other objects in the nib file.

If you are going to write a header file and then drag the file into Interface Builder, follow the conventions for header files described in ªThe Structure of Header Files and Implementation Files,º in this chapter.

Creating Classes in Project Builder

Instead of defining a class in Interface Builder and using Create Files to create the source code, you can create the source code in Project Builder first and add the class to Interface Builder later. To create a class in Project Builder, use the File ¬  New in Project command to create template source code files, write your code, then drag the header file into the nib file window. When you create a class in this manner, any method you've defined that takes a single argument named sender and that returns id or void is considered an action. Any instance variable that is type id or has the IBOutlet keyword prefixed to its declaration is an outlet. 

#import <AppKit/AppKit.h>

#define IBOutlet €€€€€€€€€€€€/* Needed to avoid compiler errors. */

@interface TAController:NSObject

{

	IBOutlet NSTableView *tableView; €€€€€€€€€€€€€€€€/* an outlet */

	id commentsLabel; €€€€€€€€€€€€€€€€€€€€€€€€€€/* another outlet */

	...

	NSMutableDictionary *countryDict; €€€€€€€€€€/* not an outlet. */

	...

}

/* target/action */

- (void)addRecord:(NSButton *)sender; €€€€€€€€€€€€€/* an action */

- (void)convertCelsius:(id)sender; €€€€€€€€€€€/* another action */

/* Data read and write methods */

- (void)populateFields:(Country *)aRec; €€€€€€€/* not an action */

@end

Copying Classes Between Nib FIles 

You can copy class definitions between nib files, in the same or different projects, by copying a class in one nib file and pasting it into another nib file.

¬

A duplicate of the original class appears in the Classes display of the destination nib file. Generate an instance of the class in the destination nib file and connect it to other objects in the nib file through its outlets and actions.