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 3751034
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:01:01+00:00 2026-05-19T09:01:01+00:00

My code is split into two main implementations: MenuController.m and AppController.m, each with header

  • 0

My code is split into two main implementations: MenuController.m and AppController.m, each with header files.

I have a couple user preferences, which are stored using NSUserDefaults, and changed via NSMenuItems so that they show check marks when enabled (using setState: NSOffState). There’s only one missing bit of my setup- I need the app to setState for those menu items on startup if the options are on in the prefs. However, the only way I know to set something on app launch is to have it in the awakeFromNib method, and that’s in the AppController and can’t access the NSMenuItem instantiated in the MenuController.

I am rather new to Objective-C, and have managed to get this far thanks to many helpful tutorials and answers on this site, but right now I’m just stumped.

I’ve tried using class and object methods to change the settings, but have failed- I need to use the existing instance of the NSMenuItems. validateMenuItem looked promising, but it only enables and disables menus and doesn’t setState.

Relevant code (I think):

from MenuController.h:

@interface MenuController : NSMenu {
 IBOutlet NSMenu *optionsMenu;
 IBOutlet NSMenuItem *onTopItem;
 IBOutlet NSMenuItem *liveIconItem;
}

- (IBAction)menuLiveIconToggle:(id)pid;

from MenuController.m: (method to change prefs and setState- works great)

- (IBAction)menuLiveIconToggle:(id)pid; {
 //NSLog(@"Live Icon Toggle");
 NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
 if ([standardUserDefaults boolForKey:@"LiveIcon"] == TRUE){
  [standardUserDefaults setBool:FALSE forKey:@"LiveIcon"];
  [liveIconItem setState: NSOffState];
 } else {
  [standardUserDefaults setBool:TRUE forKey:@"LiveIcon"];
  [liveIconItem setState: NSOnState];
 }
 [standardUserDefaults synchronize];
}

from AppController.m: (does NOT work, but this is the gist of it)

- (void) awakeFromNib{
 // Update menu items
 if ([standardUserDefaults boolForKey:@"LiveIcon"] == TRUE) {
  [liveIconItem setState: NSOnState];
 } else {
  [liveIconItem setState: NSOffState];
 }
}

Thanks for any help!

  • 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-19T09:01:02+00:00Added an answer on May 19, 2026 at 9:01 am

    There are several ways you could achieve this. First, you could simply move your awakeFromNib implementation into your MenuController class, where you have access to the outlets. awakeFromNib is not specific to the App Delegate, but available for all objects that are loaded from Nibs (as you have outlets in your MenuController, I assume that it is loaded from a Nib).

    You could also implement validateMenuItem:, always return YES, but also set the state of the menu item that is given to you as the parameter.

    Or, get rid of all the code and just use bindings in Interface Builder. You can bind the “value” (== state) of your menu item to the “Shared User Defaults Controller” and enter “LiveIcon” as the model key path. You can then delete all of the code you posted and it’ll just work.

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

Sidebar

Related Questions

In the code-behind style of ASP.NET programming, you split your code into two different
I want my Android Screen (320*480) to be split into two 2 screens each
I have a reasonably simple split view application adapted from iPhone code. The main
We have a project here which is split into two. One for Internal and
I started with a piece of code which got split into two small programs
I have the following code, which splits up a Vector into a string vector
When I write C++ code for a class using templates and split the code
Code I have: cell_val = CStr(Nz(fld.value, )) Dim iter As Long For iter =
I am new to java and I have two classes (class calc and button)
I have to upgrade one existing application and neeed to split its existing UI

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.