• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Help with NSDocument and NSWindowController subclass
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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 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.

  • Prev by Date: DIME in objective-c?
  • Next by Date: IBPalette problem
  • Previous by thread: DIME in objective-c?
  • Next by thread: Re: Help with NSDocument and NSWindowController subclass
  • Index(es):
    • Date
    • Thread