I have an ARC project involving a custom view that appears after clicking a status bar icon. I'm new to programming, so I pulled this example project from GitHub to get up and running. The app runs fine, the only issue is with the status bar item. I set up the NSStatusItem as I should, but as soon as I call setView, the icon seems to be released. I can click an empty space in the menubar which opens the app so the item is there, it's just that the icon is missing. (Image is confirmed to be valid). What am I missing?
Here's the NSStatusItem code:
//
// WOMAppDelegate.m
// PopoverMenulet
//
// Created by Julián Romero on 10/26/11.
// Copyright (c) 2011 Wuonm Web Services S.L. All rights reserved.
//
#import "WOMAppDelegate.h"
#import "WOMMenulet.h"
#import "WOMController.h"
@implementation WOMAppDelegate
@synthesize window = _window;
@synthesize menulet;
@synthesize statusItem;
@synthesize statusImage;
@synthesize controller;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
//SET UP NSSTATUSITEM
statusImage = [NSImage imageNamed:@"basket"];
self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
[self.statusItem setImage:statusImage];
//[self.statusItem setHighlightMode:YES];
[self.statusItem setEnabled:YES];
self.menulet = [[WOMMenulet alloc] init]; /* square item */
self.controller = [[WOMController alloc] init];
self.menulet.delegate = controller;
[self.statusItem setView:menulet];
}
@end
And here's the referenced menulet code:
//
// WOMMenulet.m
// PopoverMenulet
//
// Created by Julián Romero on 10/26/11.
// Copyright (c) 2011 Wuonm Web Services S.L. All rights reserved.
//
#import "WOMMenulet.h"
static void *kActiveChangedKVO = &kActiveChangedKVO;
@implementation WOMMenulet
@synthesize delegate;
- (void)setDelegate:(id<WOMMenuletDelegate>)newDelegate
{
[(NSObject *)newDelegate addObserver:self forKeyPath:@"active" options:NSKeyValueObservingOptionNew context:kActiveChangedKVO];
delegate = newDelegate;
}
- (void)mouseDown:(NSEvent *)event {
[self.delegate menuletClicked];
}
#pragma mark - KVO
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if (context == kActiveChangedKVO) {
//NSLog(@"%@", change);
[self setNeedsDisplay:YES];
}
}
@end