Saving NSView, Open and Save Always Greyed Out

Discussion in 'Mac Programming' started by nutthick, Aug 1, 2008.

  1. nutthick macrumors newbie

    Joined:
    Apr 11, 2007
    #1
    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
     
  2. MrFusion macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #2
    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...
     
  3. nutthick thread starter macrumors newbie

    Joined:
    Apr 11, 2007
    #3
    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.
     
  4. nutthick thread starter macrumors newbie

    Joined:
    Apr 11, 2007
    #4
    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.
     
  5. MrFusion macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #5
    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.
     

Share This Page