Re: Help with NSDocument and NSWindowController subclass
Re: Help with NSDocument and NSWindowController subclass
- Subject: Re: Help with NSDocument and NSWindowController subclass
- From: Ted Lowery <email@hidden>
- Date: Mon, 13 Jan 2003 22:45:38 -0500
Hi all-
Just an update, I believe I have fixed this issue. I had created an
instance of myDocument in the nib. So when the nib is loaded, an
instance of myDoc is created for me, somewhere within the NS heirarchy,
I never figured out exactly where. Then I'm sent a
makeWindowControllers, and I call [drawWindowController init], which in
turn calls initWithWindowNibName, and presto, another myDocument is
created. So I deleted the instance of myDocument from the nib, and it
seems to be working better now.
What is curious however, is that I believe I should have been leaking
the two NSArray's that I allocated in [MyDocument init], however,
MallocDebug never informed me of it.
I spent several hours chasing this. I hope my description helps
someone else.
Cheers, Ted
Begin forwarded message:
>
From: Ted Lowery <email@hidden>
>
Date: Sat Jan 11, 2003 10:42:23 PM US/Eastern
>
To: email@hidden
>
Subject: Help with NSDocument and NSWindowController subclass
>
>
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 unarchiveObjectWithData: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.