2010-12-24 2 views
15

NSMenuItem을 프로그래밍 방식으로 만들고 사용할 수 없습니다. validateMenuItem : 메서드를 재정 의하여 모든 항목에 대해 YES를 반환하면 메뉴 항목이 제대로 작동합니다.비활성화 됨 nsmenuitem

메뉴에 autoEnableItems를 지정하고 validateMenuItem : 메소드를 무시하면 활성화되지 않는 이유는 무엇입니까?

NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:label action:@selector(methodToLogSomething:) keyEquivalent:@""]; 
menuItem.representedObject = representedObject; 
[menuItem setTarget:self]; 
[menu insertItem:menuItem atIndex:[[menu itemArray] count]-1]; 
[menuItem release]; 
    [menu setAutoenablesItems:YES]; 

답변

27

대상 및 작업을 올바르게 설정하지 않으면 메뉴 항목이 비활성화 된 것처럼 보입니다. 내 경우에는 셀렉터 끝에 :을 잊어 버렸습니다.

+0

답변을 게시 해 주셔서 감사합니다. 이것은 나를 도왔다 !!! – livingtech

+0

방금 ​​이렇게 많은 시간을 절약했습니다 ... 감사합니다. –

+1

'setTarget'을 통해 목표 설정을 잊어 버렸습니다. 제대로 설정하지 마십시오. 감사! –

관련 문제