• 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
How to deal with a MenuItem with both a binded state property and an action method
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to deal with a MenuItem with both a binded state property and an action method


  • Subject: How to deal with a MenuItem with both a binded state property and an action method
  • From: "Joan Lluch (casa)" <email@hidden>
  • Date: Sat, 28 Jun 2008 00:06:12 +0200

I am struck in what should be a simple task so I would appreciate any help.

I have a menu item which I want to show a default on or off state, so I set up a binding in IB to a BOOL "monitor" property in my controller. This works ok and both the check mark in the menu item and the property are kept in sync whatever I change.

However, the menu item I am talking about is intended to trigger an action that can fail, so I want to keep its ultimate state unchanged in some cases. For this purpose I added an action method that checks the original state of the menuState property and resets it accordingly depending on the success status of the performed accion.

The code looks as follows


- (BOOL)menuState { return menuState ; }

- (void)setMenuState:(BOOL)value
    {
     NSLog(@"setMenuState (%d) called",value);
     menuState = value ;
    }


- (IBAction) myAction:(id)sender {

    do something...

    if ( fail ) [self setMenuState:NO] ;
   }

I observed that when the user clicks on the menu item the action method is called before any change is made to menuState, but then setMenuState may be called twice: one from myAction (if it fails) and one from the frameworks. The problem here is that after the second call both menuState and the menuItem no longer shows the intended state.

So I wonder what should be the right approach to accomplish this?. I can not simply assume that setMenuState will be always called after myAction because I also intent to set that same action to a toolbar button with the same function of the menu item.

Thank you for any help.

Joan Lluch _______________________________________________

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: How to deal with a MenuItem with both a binded state property and an action method
      • From: Keary Suska <email@hidden>
  • Prev by Date: Re: Losing some event
  • Next by Date: Re: Why aren't my bindings firing?
  • Previous by thread: Re: Working with Notifications and NSFileHandle
  • Next by thread: Re: How to deal with a MenuItem with both a binded state property and an action method
  • Index(es):
    • Date
    • Thread