Help with NSDocument and NSWindowController subclass
Help with NSDocument and NSWindowController subclass
- Subject: Help with NSDocument and NSWindowController subclass
- From: Ted Lowery <email@hidden>
- Date: Sat, 11 Jan 2003 22:42:23 -0500
Hi all-
I've tried to setup my NSDocument subclass to use a NSWindowController
subclass, rather than the default. However, [myDocument init] is being
called twice, once by [NSDocumentController
makeUntitledDocumentOfType:] and then once by [NSCustomObject
nibInstantiate], probably as a result of my call to if (self = [super
initWithWindowNibName:@"MyDocument"]).
In my nib, I've changed the files owner to be my NSWindowController
subclass, and then created an instance of MyDocument. Here are the
implementations.
What have I done wrong?
Thanks...Ted
@implementation MyDocument
- (id)init { debug;
self = [super init];
if (self) {
objects = [[NSMutableArray alloc] init];
selection = [[NSMutableArray alloc] init];
}
return self;
}
- (void)dealloc { debug;
[objects release];
[selection release];
[super dealloc];
}
#pragma mark -
- (NSArray*)objects { debug;
return objects;
}
- (void)addObject:(id)anObject { debug;
[objects addObject:anObject];
[self updateChangeCount:nil];
}
#pragma mark -
- (void)makeWindowControllers { debug;
drawWindowController = [[DrawWindowController alloc] init];
[self addWindowController:drawWindowController];
}
- (void)windowControllerDidLoadNib:(NSWindowController*)aController {
debug;
[super windowControllerDidLoadNib:aController];
// Add any code here that needs to be executed once the
windowController has loaded the document's window.
}
- (NSData *)dataRepresentationOfType:(NSString *)aType { debug;
return [NSArchiver archivedDataWithRootObject:objects];
}
- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
{ debug;
[objects release];
objects = [[NSUnarchiver unarchiveObjectWith
Data:data] retain];
[window setViewsNeedDisplay:YES];
return YES;
}
@implementation DrawWindowController
#pragma mark -
- (id)init { debug;
if (self = [super initWithWindowNibName:@"MyDocument"])
;
return self;
}
- (void)dealloc { debug;
[super dealloc];
}
- (void)windowDidBecomeKey:(NSNotification *)aNotification { debug;
[NSApp setDocWindow:[self window]];
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.