> I have tried to implement the 'save file' action in a simple
> calculator program to no avail. The program works fine, but when the
[quoted text clipped - 7 lines]
> http://students.millikin.edu/~jstevens/Calculator.h
> http://students.millikin.edu/~jstevens/Calculator.m
You've really verified that in encodeWithCoder: the object values are
wrong? It's not in the read later?
What warnings do you get when building? (And if you don't get any, turn
warnings on, because there's certainly warnable code in there.)
(BTW: [super dealloc] should be the last thing in dealloc, not the
first.)
james@clearknightstudios.com - 13 Mar 2007 16:59 GMT
In the NSLog statement in encodeWithCoder: I test the value of top and
it is always set to the initial value 0 no matter how the program has
changed it. I've done this with the other variable as well.
I do have warnings turned on, and I don't get any with the way the
code is now... Where should I be?
Thanks,
- James
> You've really verified that in encodeWithCoder: the object values are
> wrong? It's not in the read later?
[quoted text clipped - 4 lines]
> (BTW: [super dealloc] should be the last thing in dealloc, not the
> first.)
> I have tried to implement the 'save file' action in a simple
> calculator program to no avail. The program works fine, but when the
[quoted text clipped - 10 lines]
> Thanks,
> - James
I tried building an app using your source. I didn't play with it much,
but your initWithCoder: worked fine, and your encodeWithCoder: worked
fine.
numberStack wasn't the initial value, [], it was [0]. When I set it to
[12] in the debugger, the program created a document that it then read
in correctly.
It is hard to tell, from the fragment you posted, but:
MyDocument never calls setCurrentEntry: with the value of any text
fields, so unless you are using cocoa bindings to bind calc.currentEntry
to a text field, text never gets in to your calculator.
Did you actually set breakpoints throughout your code and verify that
numberStack is what you expect by typing
po numberStack
in the Console Log window (from the Debug menu in Xcode)?
james@clearknightstudios.com - 14 Mar 2007 14:41 GMT
I have tested the value of numberStack throughout the program. It is
always fine until I try to save the document. I think the problem may
be some kind of NSObjectController is needed, but I'm not sure at
all. I haven't set any bindings to the textfields because they are
set in the method setDisplayViewAtStartingLine: in MyDocument. This
method is called when a file is opened.
I have uploaded the entire project, so the nib file can be viewed. If
anyone has some free time to take a look, I'm still stumped.
http://students.millikin.edu/~jstevens/Calculator.zip
Thanks a lot,
- James
> In article <1173762180.262886.261...@q40g2000cwq.googlegroups.com>,
>
[quoted text clipped - 34 lines]
>
> in the Console Log window (from the Debug menu in Xcode)?
David Phillip Oster - 14 Mar 2007 15:21 GMT
> I have tested the value of numberStack throughout the program. It is
> always fine until I try to save the document. I think the problem may
[quoted text clipped - 7 lines]
>
> http://students.millikin.edu/~jstevens/Calculator.zip
Your MyDocument.nib contains a File's Owner, set to class MyDocument,
and another object, an instance, set to MyDocument. if you set
breakpoints on Calculator's init, you'll see that init is being called
twice for each use of the nib.
The second "MyDocument" in the nib is incorrect. Delete it, and just
make all the connections to the "File's Owner".
james@clearknightstudios.com - 14 Mar 2007 15:52 GMT
That was it. The variables now get saved and read back in. Thanks a
lot!
There is one more small problem. The method setCalc is called when a
file is opened. At the end of the method
setDisplayViewAtStartingLine: is called, but the textfields are not
updated with the contents of the number stack. If I enter a new
number, however, the whole stack then appears as should. Why isn't it
initially appearing?
> In article <1173879691.205945.200...@l75g2000hse.googlegroups.com>,
>
[quoted text clipped - 18 lines]
> The second "MyDocument" in the nib is incorrect. Delete it, and just
> make all the connections to the "File's Owner".
Gregory Weston - 14 Mar 2007 19:11 GMT
> That was it. The variables now get saved and read back in. Thanks a
> lot!
[quoted text clipped - 5 lines]
> number, however, the whole stack then appears as should. Why isn't it
> initially appearing?
First guess: During document open the document's outlets have not yet
been set to point to the NIB objects so you're sending messages to nil.
G
David Phillip Oster - 15 Mar 2007 03:17 GMT
> That was it. The variables now get saved and read back in. Thanks a
> lot!
[quoted text clipped - 5 lines]
> number, however, the whole stack then appears as should. Why isn't it
> initially appearing?
Many of apple's examples store the open path in a variable in the
document, and do the actual work of opening the file in awakeFromNib
See for example:
/Developer/Examples/AppKit/SimpleComboBox/CDInfoDocument.m
- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType;
just saves the NSData for later, while the actual unarchiving happens in
- (void)windowControllerDidLoadNib:(NSWindowController *) aController;
james@clearknightstudios.com - 28 Mar 2007 02:49 GMT
> In article <1173883939.336497.325...@l77g2000hsb.googlegroups.com>,
>
[quoted text clipped - 20 lines]
>
> - (void)windowControllerDidLoadNib:(NSWindowController *) aController;
Thanks a lot David! That was the key.