xcode에서 간단한 메뉴 모음 만 응용 프로그램을 만들려고합니다. 모든 것이 실제로 작동하지만, 아이콘이 메뉴 모음에 두 번 나타나는 것을 이해하지 못합니다. 두 아이콘 중 하나는 실제로 작동하고 작동 버튼이있는 드롭 다운 메뉴를 제공하고, 다른 아이콘은 클릭 한 상태에서 강조 표시된 아이콘 이미지로 변경되고 아무 것도하지 않고 돌아갈 때 드롭 다운 메뉴가 나타나지 않습니다.이중 상태 항목 아이콘이 나타납니다
- (void) awakeFromNib{
//Create the NSStatusBar and set its length
statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];
//Used to detect where the files are
NSBundle *bundle = [NSBundle mainBundle];
//Allocates and loads the images into the application which will be used for the NSStatusItem
statusImage = [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:@"icon" ofType:@"png"]];
statusHighlightImage = [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:@"icon-alt" ofType:@"png"]];
//Sets the images in the NSStatusItem
[statusItem setImage:statusImage];
[statusItem setAlternateImage:statusHighlightImage];
//Tells the NSStatusItem what menu to load
[statusItem setMenu:statusMenu];
//Sets the mouse over text
[statusItem setToolTip:@"My Custom Menu Item"];
//Enables highlighting
[statusItem setHighlightMode:YES];
다음 이미지
- (void) dealloc {
//Releases the 2 images we loaded into memory
[statusImage release];
[statusHighlightImage release];
[super dealloc];
와 헤더 파일 해제 : 로그에 IBAction를 가진
@interface MenuletApp : NSObject <NSApplicationDelegate> {
NSWindow *window;
IBOutlet NSMenu *statusMenu;
NSStatusItem *statusItem;
NSImage *statusImage;
NSImage *statusHighlightImage;
에게 안녕하세요
이것은 내가 발견하고 밖으로 테스트 코드입니다 항목 중 하나가 클릭되면 월드, 다른 항목이 클릭되면 종료됩니다.
XCode 3 용 튜토리얼을 사용 했으므로 단계 중 하나가 다르게 수행되었지만 코드를 살펴보면 두 번째 상태 항목이 어디에서 생성되는지 알 수 없습니다.
도움 주셔서 감사합니다.
질문자는이 클래스의 두 객체를 두 개의 개별 닙에서 사용할 수 있습니다. (아마도 그들은 어떻게 든 결합되어 하나의 객체가 될 것이라는 잘못된 믿음으로)이 객체가 코코아에서 고유 한 코코아를로드하도록 할 수 있습니다. 펜촉의 소유자는 또한 'awakeFromNib' 메시지를 보냅니다. 어느 쪽이든 결과는 동일하며 제안 된 솔루션에 동의합니다. –
appDidFinishLaunching으로 이동하면됩니다. 감사! – Elbimio