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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:05:13+00:00 2026-05-31T09:05:13+00:00

I have a NSMenuItem with a custom view. However, when I want to update

  • 0

I have a NSMenuItem with a custom view. However, when I want to update the first row in the menu it add the content as it is in the xib file, not as I set it.

My code:
AppDelegate.m:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    _helper = [[Helper alloc] init];

    statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
    [statusItem setMenu:self.statusMenu];
    [statusItem setTitle:@"GravAccount"];
    [statusItem setHighlightMode:YES];

    _gravatarLoader = [[GravatarLoader alloc] initWithTarget:self andHandle:@selector(setGravatarImage:)];

    // Get email address
    _email = [_helper getEmailAddress];

    if (_email != nil)
    {
        [_gravatarLoader loadEmail:_email withSize:50.0];
    }
}

- (void)setGravatarImage:(NSImage*)image
{
    NSLog(@"Image loaded!");

    GravatarMenuItem *menuItem = [[GravatarMenuItem alloc] initWithNibName:@"GravatarMenuItem" bundle:nil];
    [menuItem.label setTitle:_email];
    [menuItem.imageView setImage:image];

    NSLog(@"Email: %@", _email);

    NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
    [item setView:menuItem.view];

    [self.statusMenu removeItemAtIndex:0];
    [self.statusMenu insertItem:item atIndex:0];
}

GravatarMenuItem.h:

#import <Cocoa/Cocoa.h>

@interface GravatarMenuItem : NSViewController

@property (nonatomic, strong) IBOutlet NSImageView *imageView;
@property (nonatomic, strong) IBOutlet NSTextFieldCell *label;

@end

The outlets are linked in the XIB file on the file’s owner.

This is the result:
Log:

2012-03-09 16:57:24.314 appName[51158:403] Image loaded!
2012-03-09 16:57:24.316 appName[51158:403] Email: Paul@******.se

Result:
Result

  • 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-31T09:05:14+00:00Added an answer on May 31, 2026 at 9:05 am

    When you do:

    GravatarMenuItem *menuItem = [[GravatarMenuItem alloc] initWithNibName:@"GravatarMenuItem" bundle:nil];
    

    It only creates the view controller. It doesn’t actually load the view from the nib. When you access the properties, they are most likely nil as the view has not been loaded (and the connections have not been made).

    If you update your code to the following, everything should work fine:

    GravatarMenuItem *menuItem = [[GravatarMenuItem alloc] initWithNibName:@"GravatarMenuItem" bundle:nil];
    [menuItem view]; // load the view from the nib
    [menuItem.label setTitle:_email];
    [menuItem.imageView setImage:image];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have added a custom view to my subclass of NSMenuItem (which sits in
I have an NSMenuItem titled Word Wrap in my main menu (MainMenu.xib). Its value
Have deployed numerous report parts which reference the same view however one of them
I created a custom view class because I wanted to have a status item
I have an NSStatusItem that has an NSMenuItem which contains a custom NSView. this
I have an NSMenuItem that I need to update to show a progress (like
I have an NSMenuItem with a bunch of items in it, however... the list
menuBar = new JMenuBar(); // File Menu JMenu fileMenu = new JMenu(File); menuBar.add(fileMenu); //
I have an NSMenuItem. I want the state aka value aka checkmark of the
I have overriden - (BOOL)validateMenuItem:(NSMenuItem *)menuItem All NSMenuItems of my menu are passed to

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.