메뉴 바 항목을 표시하는 방법은 테이블에 몇 행이 있는지 표시합니까?

StackOverflow https://stackoverflow.com/questions/823570

  •  05-07-2019
  •  | 
  •  

문제

핵심 데이터 테이블이 있고 메뉴 표시 줄 항목에 테이블에 얼마나 많은 행이 있는지 표시하려고합니다. 이 코드를 사용하여 이미 메뉴 표시 줄 항목을 만들었습니다.

 -(void)applicationDidFinishLaunching:(NSNotification *)aNotification { 
NSStatusItem *statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain]; //Create new status item instance
[statusItem setHighlightMode:YES]; //This does something, I'm sure of it.
[statusItem setTitle:[NSString stringWithFormat:@"%C",0xff50]]; //This labels it. You can also use setImage instead to use an icon. That current code will result in a item labeled "p"
[statusItem setEnabled:YES]; //Self explanatory
[statusItem setMenu:theMenu];
[statusItem setToolTip:@"TOOLTIP HA AWESOME AMIRITE?"]; //Optional, just for kicks.
}

메뉴 막대 항목을 표시하려면 무엇을 추가해야합니까? 테이블에 몇 행이 얼마나 있습니까?

도움이 되었습니까?

해결책

라이브 업데이트가 필요하지 않으면이 접근법을 시도 할 수 있습니다.

1) Themenu의 대의원을 설정하십시오.

[theMenu setDelegate:self];

2) 대의원을 구현하십시오.

- (void)menuWillOpen:(NSMenu *)menu {
    NSUInteger count = [self.tableView numberOfRows];
    [[menu itemAtIndex:0] setTitle: [NSString stringWithFormat:@"%d rows", count]];
}

이 코드는 사용자가 메뉴를 열 때마다 메뉴 항목을 새로 고침합니다. 테이블의 무언가가 변경 될 때마다 새로 고침하려면 어레이 컨트롤러를 관찰하려면 KVO를 사용해야합니다. 상태 제목에 카운트를 표시하려면 KVO를 사용해야합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top