NSStatusItem how i can setAction and show menu ?

Discussion in 'Mac Programming' started by artbeat.easy, Aug 5, 2010.

  1. artbeat.easy macrumors newbie

    Jul 1, 2010
    Hello all )
    I have some problem
    if i set Action on NSStatusItem i can't show menu ((

    NSStatusItem*statusItem …

    [statusItem setMenu:…]
    [statusItem setAction:…]

    not work (( how i can handle click and show menu ?
  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    You can't. You can do one or the other, not both.

    From the NSStatusItem reference doc for setMenu:
    When set, the receiver’s single click action behavior is not used.
  3. artbeat.easy thread starter macrumors newbie

    Jul 1, 2010
    ok ( how i can handle menu open ? or how i can show menu ? if i handle mouse click ( setAction ) i can show menu manual ?
  4. LinusR macrumors regular


    Jan 3, 2011
    Put in your method to call while clicking on the status item this code:
    [theStatusItem popUpStatusItemMenu:theStatusMenu]
    So for example:
    - (void) awakeFromNib{
        statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];
        [statusItem setAction:@selector(statusItemClicked)];
        [statusItem setTarget:self];
    - (void)statusItemClicked {
        [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(showMenu) userInfo:nil repeats:NO];
        [NSApp activateIgnoringOtherApps:YES];
        [statusItem popUpStatusItemMenu:statusMenu];
    Hope that helps.

Share This Page