Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

nutthick

macrumors newbie
Original poster
Apr 11, 2007
26
0
I'm working my way through Aaron Hillegass's book and am completing the challenge for Chapter 18.

I have a Cocoa App that draws ovals onto an Custom View. Undo/Redo is working, with all the code held in a NSView subclass. I'm having trouble getting loading and saving to trigger. I have included the following in my header
Code:
@interface ovalDraw : NSView <NSCoding> {
and have implemented the following methods
Code:
- (void)encodeWithCoder:(NSCoder *)coder
- (id)initWithCoder:(NSCoder *)coder
- (NSData *)dataOfType:(NSString *)aType
				 error:(NSError **)outError
- (BOOL)readFromData:(NSData *)data
			  ofType:(NSString *)typeName
			   error:(NSError **)outError
Everything compiles and runs, but Open and Save are always greyed out on the App menu. The connections I have tried in IB don't seem to make a difference, and the methods above never get called.

All the data is held in a NSMutableArray and I'm not using an array controller.

Can anyone help with this, as I'm running out of ideas.

Thanks
 

MrFusion

macrumors 6502a
Jun 8, 2005
613
0
West-Europe
I'm working my way through Aaron Hillegass's book and am completing the challenge for Chapter 18.

I have a Cocoa App that draws ovals onto an Custom View. Undo/Redo is working, with all the code held in a NSView subclass. I'm having trouble getting loading and saving to trigger. I have included the following in my header
Code:
@interface ovalDraw : NSView <NSCoding> {
and have implemented the following methods
Code:
- (void)encodeWithCoder:(NSCoder *)coder
- (id)initWithCoder:(NSCoder *)coder
- (NSData *)dataOfType:(NSString *)aType
				 error:(NSError **)outError
- (BOOL)readFromData:(NSData *)data
			  ofType:(NSString *)typeName
			   error:(NSError **)outError
Everything compiles and runs, but Open and Save are always greyed out on the App menu. The connections I have tried in IB don't seem to make a difference, and the methods above never get called.

All the data is held in a NSMutableArray and I'm not using an array controller.

Can anyone help with this, as I'm running out of ideas.

Thanks

I don't have a good answer for your problem, but did you implement enough methods for you app to actually be able to save and load data? Maybe you forgot some delegate method?
Grayed out menu's is usually because there is no responder for that method, or maybe because you didn't implement this method
Code:
- (BOOL)validateMenuItem:(id <NSMenuItem>)menuItem;

When you create a new (document) project, you get the standard save and open methods. Can't you use those? just asking...
 

nutthick

macrumors newbie
Original poster
Apr 11, 2007
26
0
I'll give it a try. I must be missing something as if the undo mechanism is working then the document should be flagged as dirty. This in theory would enable the menu items.

This is driving me nuts, I'm about to try a totally different architecture to see if that makes a difference.
 

nutthick

macrumors newbie
Original poster
Apr 11, 2007
26
0
I was trying to make things too complicated for where I am in the book. The solution was much simpler. Like MrFusion said, I just used more standard open and save methods to sort it out.
 

MrFusion

macrumors 6502a
Jun 8, 2005
613
0
West-Europe
I was trying to make things too complicated for where I am in the book. The solution was much simpler. Like MrFusion said, I just used more standard open and save methods to sort it out.

One thing I learned about developing with xCode and Cocoa, is not to fight it. Use the standard functions/methods and you'll do great.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.