-document works inconsistently in NSWindowController subclass
-document works inconsistently in NSWindowController subclass
- Subject: -document works inconsistently in NSWindowController subclass
- From: Charlton Wilbur <email@hidden>
- Date: Fri, 19 Nov 2004 04:36:50 -0500
All,
This may wind up just being confessional debugging, but I'm stumped.
I'm working on a document-based application; it will read and write
two different document types, and each document type will have a
couple different views. As a result, I'm subclassing NSDocument and
NSWindowController. In my subclass of NSDocument, I call
-makeWindowControllers like so:
- (void) makeWindowControllers
{
DataEditorMainWindow *mainwin = [[DataEditorMainWindow alloc] init];
[self addWindowController: mainwin];
NSLog (@"in makeWindowControllers, [mainwin document] is %@",
[mainwin document]);
NSLog (@"and [[mainwin document] datasheet] is %@", [[mainwin
document] datasheet]);
}
In particular, those two NSLog statements indicate that [mainwin
document] points to an object of the right class and that the
datasheet is correct. The debugging log indicates further, through
NSLog statements in -windowDidLoad, that [self document] works
correctly there, and returns the same values that were returned in
-makeWindowControllers.
But in the window that's being instantiated, there's an NSOutlineView,
which calls the window controller's
outlineView:numberOfChildrenOfItem: method, passing in nil as the item
to get the number of top-level items. In *that* method, which I
implement like so:
- (int) outlineView: (NSOutlineView *) outlineView
numberOfChildrenOfItem: (id) item
{
NSLog (@"outlineView:numberOfChildrenOfItem: called, item %@",
[item description]);
NSLog (@"[self document] is %@", [[self document] description]);
NSLog (@"[[self document] datasheet] is %@", [[[self document]
datasheet] description]);
int result;
if (item == nil)
result = [[[self document] datasheet] classCount];
else
result = [[[self document] datasheet] countObjectsOfClass: item];
NSLog (@"answering %d", result);
return result;
}
the NSLog statements reveal that [self document] is nil, and I have no idea why.
In the even that it helps, here's some of the debugging log:
[Session started at 2004-11-19 04:30:31 -0500.]
2004-11-19 04:30:32.575 Blackthorn[2069] in makeWindowControllers,
[mainwin document] is <DataEditorDocument: 0x3423b0>
2004-11-19 04:30:32.578 Blackthorn[2069] and [[mainwin document]
datasheet] is {Advantages = (); Skills = (); }
2004-11-19 04:30:32.792 Blackthorn[2069]
outlineView:numberOfChildrenOfItem: called, item (null)
2004-11-19 04:30:32.792 Blackthorn[2069] [self document] is (null)
2004-11-19 04:30:32.792 Blackthorn[2069] [[self document] datasheet] is (null)
2004-11-19 04:30:32.792 Blackthorn[2069] answering 0
2004-11-19 04:30:32.938 Blackthorn[2069] DataEditorMainWindow loaded
2004-11-19 04:30:32.939 Blackthorn[2069] [self document] is
<DataEditorDocument: 0x3423b0>
2004-11-19 04:30:32.940 Blackthorn[2069] [[self document] datasheet]
is {Advantages = (); Skills = (); }
2004-11-19 04:30:35.382 Blackthorn[2069] addRow button pushed, adding
2004-11-19 04:30:35.383 Blackthorn[2069] [self document] is (null)
2004-11-19 04:30:35.383 Blackthorn[2069] [[self document] datasheet] is (null)
Executable "Blackthorn" has exited with status 0.
What it looks like to me is that perhaps objects that use any of the
NSOutlineView delegate methods, or the Interface Builder actions,
don't see the same self object as the rest of the objects in the
class. I'm hoping that I'm doing something obviously stupid, or that
this is something one of the wiser heads on this list has run into in
the past.
Thanks for any assistance,
Charlton
--
Charlton Wilbur
email@hidden
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden