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

  • SEARCH
  • Home
  • 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 196829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:48:03+00:00 2026-05-11T16:48:03+00:00

I have already created a status item for the menu bar but I would

  • 0

I have already created a status item for the menu bar but I would like to add a checkbox to make it able to be toggled on and off.

So when the check box is checked the status item is displayed and when the checkbox is not checked it is not displayed.

What code would i need to do this?

  • 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-11T16:48:03+00:00Added an answer on May 11, 2026 at 4:48 pm

    First in your controller class create an instance variable to hold the reference to this item:

    NSStatusItem *item;
    

    Then create a method to create this status item, when the box is checked:

    - (BOOL)createStatusItem
    {
    NSStatusBar *bar = [NSStatusBar systemStatusBar];
    
    //Replace NSVariableStatusItemLength with NSSquareStatusItemLength if you
    //want the item to be square
    item = [bar statusItemWithLength:NSVariableStatusItemLength];
    
    if(!item)
      return NO;
    
    //As noted in the docs, the item must be retained as the receiver does not 
    //retain the item, so otherwise will be deallocated
    [item retain];
    
    //Set the properties of the item
    [item setTitle:@"MenuItem"];
    [item setHighlightMode:YES];
    
    //If you want a menu to be shown when the user clicks on the item
    [item setMenu:menu]; //Assuming 'menu' is a pointer to an NSMenu instance
    
    return YES;
    }
    

    Then create a method to remove the item when it is unchecked:

    - (void)removeStatusItem
    {
    NSStatusBar *bar = [NSStatusBar systemStatusBar];
    [bar removeStatusItem:item];
    [item release];
    }
    

    Now tie it all together by creating an action that is called when the checkbox is toggled:

    - (IBAction)toggleStatusItem:(id)sender
    {
    BOOL checked = [sender state];
    
    if(checked) {
      BOOL createItem = [self createStatusItem];
      if(!createItem) {
        //Throw an error
        [sender setState:NO];
      }
    }
    else
      [self removeStatusItem];
    }
    

    Then create the checkbox in IB and set the action to your toggleStatusItem: method; make sure that the checkbox is left unchecked.

    Edit (In response to errors)
    As stated above, you need to declare the NSStatusItem in the interface of the class that you have placed the createStatusItem and removeStatusItem methods; the reason that this becomes an instance variable rather than one local to the createStatusItem method is that there is no way to retrieve a pointer to an item that has already been added to the status bar in the Apple menu, and in order to remove the item once the checkbox is unchecked, you must store a pointer to this item. This will also solve your third error.

    In response to your second error, I was merely demonstrating that if you want to add a menu to your status item when it is clicked, you must add the code for that yourself, retrieving a pointer to an NSMenu; I was showing how you could then add this menu item to the status bar item, if your pointer was called menu, hence my comment next to the line of code.

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

Sidebar

Related Questions

I have already created a webpart to show the data from list, but I
I have this application that shows an item in the system's status bar, and
I have already created my application on web socket with ASP.net 4.0. I just
I am building an Day View calendar app. I have already created the empty
I have two User Controls already created now I want to use one as
I have created a turing-complete programming language (already proven) so it must be possible
I was already running a sub-website under following path http://example.com/sub-site/ Now, I have created
I currently have the following MySQL query, which I would like to include in
I'm building an app that takes status updates from several Social Media. Already have
I would like to read the deleted statuses on twitter since i can already

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.