Re: How to deal with a MenuItem with both a binded state property and an action method
Re: How to deal with a MenuItem with both a binded state property and an action method
- Subject: Re: How to deal with a MenuItem with both a binded state property and an action method
- From: Keary Suska <email@hidden>
- Date: Fri, 27 Jun 2008 16:23:57 -0600
- Thread-topic: How to deal with a MenuItem with both a binded state property and an action method
6/27/08 4:06 PM, also sprach email@hidden:
> 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.
When using bindings always stick to MVC--i.e., don't touch the menu. If you
have to change the state, change the "monitor" value to reflect the correct
state. IN any case, you don't say how the menuState property enters into the
picture, vs the "monitor" property.
HTH,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
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