No callback when clicking menu item

删除回忆录丶 提交于 2019-12-04 19:20:29

Apparently, callbacks will only work if the target is the instance of FinderSync. Could not find any documentation to support this theory, but the only thing that fixed the problem was moving the context menu code into MyFinderSync.m:

...
- (NSMenu *)menuForMenuKind:(FIMenuKind)whichMenu {

    NSMenu *myContextMenu = [[NSMenu alloc] initWithTitle:@""];

    @try
    {
        if(whichMenu != FIMenuKindContextualMenuForItems) {
            return myContextMenu;
        }

        myContextMenu = [self buildMenu];
    }
    @catch (NSException *ex)
    {
    }

    return myContextMenu;
}

- (NSMenu *)buildMenu
{
    NSMenu *mySubmenu = [[NSMenu alloc] initWithTitle:@""];

    NSMenuItem *newMenu = [[NSMenuItem alloc] initWithTitle:@"hello"
                                                     action:@selector(callback:)
                                              keyEquivalent:@""];
    [newMenu setTarget:self];
    [mySubmenu addItem:newMenu];

    return mySubmenu;
}

- (void) callback              : (id)sender {
    NSLog(@"Called back!!!");
}
...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!