• 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
NSDocument Enabling and handling menu items without implementing the action method in the document class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSDocument Enabling and handling menu items without implementing the action method in the document class


  • Subject: NSDocument Enabling and handling menu items without implementing the action method in the document class
  • From: Eyal Redler <email@hidden>
  • Date: Sun, 19 Jul 2009 15:06:00 +0300

Hi,

In the document based application I'm working on I have a lot of methods in the document class which simply pass a command to some internal object. This requires me do do the following in my NSDocument subclass:

- (BOOL)validateMenuItem:(NSMenuItem *)item
{
    SEL action = [item action];

    if (action==@selector(myAction:))
        return [internalObject shouldEnableMyAction];
    else
      ...

}

- (void)myAction:(id)sender
{
    [internalObject myAction:sender];
}

This works fine but it requires me to write an annoying amount such glue code every time I add an action so I'm looking for a better way to do this. Is it possible to further delegate the action methods and menu validation from the NSDocument subclass? The best way for me would be to have internalObject implement validateMenuItem and myAction and have the NSDocument pass them along without actually implementing each action method.

TIA

Eyal

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSDocument Enabling and handling menu items without implementing the action method in the document class
      • From: Graham Cox <email@hidden>
  • Prev by Date: Re: [IB] - how to delete action or outlet?
  • Next by Date: Re: iPhone runtime browser.
  • Previous by thread: Re: Ideas required on testing an application install
  • Next by thread: Re: NSDocument Enabling and handling menu items without implementing the action method in the document class
  • Index(es):
    • Date
    • Thread