몇 달 동안 아무 작업도하지 않으면 코코아 개발로 돌아 오기 시작합니다. 원래 내가 시작했을 때 저는 Snow Leopard와 Xcode 3을 사용했습니다. 이제 Xcode 4.2로 라이온을 실행 중이며 이전에 실행하지 못한 몇 가지 문제가 있습니다.NSStatusItem이 시작될 때 잠시 나타나지만 즉시 사라집니다.
저는 이전에 ARC를 사용 해본 적이 없다고 생각합니다. 그래서 나는 뭔가를 놓치고 있다고 확신합니다.
주 창이나 도킹 아이콘없이 상태 표시 줄 응용 프로그램을 만들려고합니다. 응용 프로그램을 실행하면 응용 프로그램의 상태 표시 줄 아이콘이 잠시 동안 잠깐 동안 나타나지만 사라집니다.
Heres my code. 당신이 내 코드와 아무 잘못 표시되는 경우
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
편집 알려 주시기 바랍니다. 나는 내가 더 잘할 수있게하는 약간의 비평을 명확히 할 것이다.
다른 편집 주 창 자체가로드 될 때 상태 표시 줄 아이콘이 사라지는 것처럼 보입니다.
코드에 대한 제안 : 현재 이미지로드 코드 대신 [appBundle imageForResource : @ "statusItemIcon"]을 사용하십시오. 더 빨라지고 @ 2x 이미지를 투명하게 지원하고, 코드를 변경하지 않고 non-png를 지원하고 읽을 수 있어야합니다. –
@Catfish_Man Thank You! 그게 정확히 제가 찾고있는 종류의 비판입니다! –