Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 603335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:55:10+00:00 2026-05-13T16:55:10+00:00

I am having some issues binding an NSMenuItem’s value binding to a BOOL. I

  • 0

I am having some issues binding an NSMenuItem’s “value” binding to a BOOL.

I simplified the problem to this:

1) The menu item must call the action method that changes the value of the BOOL otherwise it doesn’t work (i.e. if an NSButton calls a method that changes the value of the BOOL then the menu item won’t update)

2) Even if the action method makes the BOOL a constant (i.e. enabled = YES), the “value” of the menu item still alternates.

Any ideas? I’m so confused!

Here is the code:

MenuBindings_AppDelegate.h

#import <Cocoa/Cocoa.h>

@interface Menu_BindingsAppDelegate : NSObject <NSApplicationDelegate> 
{   
   BOOL foo;
}

- (IBAction)toggle:(id)sender;
- (IBAction)makeYes:(id)sender;

@property BOOL foo;

@end

Menu_BindingsAppDelegate.m

@implementation Menu_BindingsAppDelegate

@synthesize foo;

- (IBAction)toggle:(id)sender
{
   [self setFoo:!foo];
}

- (IBAction)makeYes:(id)sender
{   
   [self setFoo:YES];
}

@end

In my nib, I have a button connected to the -makeYes: action and a menu item connected to the -toggle: action. The menu item’s “value” binding is bound to the app delegate’s “foo” attribute.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T16:55:11+00:00Added an answer on May 13, 2026 at 4:55 pm

    Cocoa Bindings uses Key-Value Observing (KVO) to obtain notification of changes in model objects. In order for the change in the model (your BOOL value) to be noticed by observers including any views that use bindings, you must update the model using Key-Value Coding-compliant accessor methods. If you just set the value of the ivar directly, no KVO notifications will be sent.

    You can either implement the KVC accessors yourself or declare a property and use the @synthesize keyword in your implementation to have the compiler create compliant accessors for you.

    This is how you would implement KVC-compliant accessors:

    //YourModel.h
    @interface YourModel : NSObject
    {
        BOOL enabled;
    }
    - (BOOL)enabled;
    - (void)setEnabled:(BOOL)flag;
    @end
    
    //YourModel.m
    @implementation YourModel
    - (BOOL)enabled
    {
        return enabled;
    }
    - (void)setEnabled:(BOOL)flag
    {
        enabled = flag;
    }
    @end
    

    and this is how you would do the same thing using Objective-C 2.0 property syntax:

    //YourModel.h
    @interface YourModel : NSObject
    {
        BOOL enabled;
    }
    @property BOOL enabled;
    @end
    
    //YourModel.m
    @implementation YourModel
    @synthesize enabled;
    @end
    

    You can then call [yourModel setEnabled:YES] and any registered KVO observers (including your menu binding) will be informed of the change.

    Alternatively, you can call yourModel.enabled = YES which will use the proper KVC accessors if available.

    I uploaded a sample project to demonstrate how it’s done.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 326k
  • Answers 326k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In fact, it really is private. Maybe your confusing with… May 14, 2026 at 1:47 am
  • Editorial Team
    Editorial Team added an answer POCO has a HTTP server, among lots of other useful… May 14, 2026 at 1:47 am
  • Editorial Team
    Editorial Team added an answer This is not a mode of deployment that is supported… May 14, 2026 at 1:47 am

Related Questions

I am attempting to create an AttachedProperty for a DataGridColumn within Silverlight 3.0 and
Hi Is it acceptable to override the Render method when creating a custom web
For some reason I'm having issues Binding a custom User Control up through my
I have recently stumbled across an issue where the WPF ListView control seems to
I am trying to produce a C# wrapper for a COM object that I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.