数か月間何も作業をしなかった後、私は Cocoa 開発に戻り始めています。始めた当初は、Snow Leopard と Xcode 3 を使用していました。現在、Xcode 4.2 で Lion を実行していますが、これまで遭遇したことのない問題に直面しています。
おそらく、これまで ARC を使用したことがないため、何かが欠けていると確信しています。
メイン ウィンドウまたはドック アイコンなしで、Statusbar アプリケーションを作成しようとしています。アプリケーションを実行すると、アプリケーションのステータスバー アイコンが短時間 (約 1 秒間) 表示されますが、その後消えます。
これが私のコードです。
QuickPlusAppDelegate.h
#import <Cocoa/Cocoa.h>
@interface QuickPlusAppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window;
@property (assign) NSStatusItem *statusItem;
@property (weak) IBOutlet NSMenu *statusItemMenu;
@property (strong) NSImage *statusItemIcon;
@property (strong) NSImage *statusItemIconHighlighted;
@property (strong) NSImage *statusItemIconNewNotification;
@end
QuickPlusAppDelegate.m
#import "QuickPlusAppDelegate.h"
@implementation QuickPlusAppDelegate
@synthesize statusItemMenu = _statusItemMenu;
@synthesize window = _window, statusItem = _statusItem;
@synthesize statusItemIcon = _statusItemIcon,
statusItemIconHighlighted = _statusItemIconHighlighted,
statusItemIconNewNotification = _statusItemIconNewNotification;
- (void) awakeFromNib
{
NSBundle *appBundle = [NSBundle mainBundle];
_statusItemIcon = [[NSImage alloc] initWithContentsOfFile:[appBundle pathForResource:@"statusItemIcon" ofType:@"png"]];
_statusItemIconHighlighted = [[NSImage alloc] initWithContentsOfFile:[appBundle pathForResource:@"statusItemIconHighlighted" ofType:@"png"]];
_statusItemIconNewNotification = [[NSImage alloc] initWithContentsOfFile:[appBundle pathForResource:@"statusItemIconNewNotification" ofType:@"png"]];
_statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
[_statusItem setImage:_statusItemIcon];
[_statusItem setAlternateImage:_statusItemIconHighlighted];
[_statusItem setHighlightMode:YES];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// empty
}
@end
編集私のコードに何か問題がある場合は、お知らせください。私は間違いなくいくつかの批評をして、私がより良くなることができるようにします.
別の編集メインウィンドウ自体がロードされると、ステータスバーアイコンが消えるようです。