0

我需要为表格的选定行创建一个菜单,我可以通过覆盖来创建

-(NSMenu*)menuForEvent:(NSEvent*)evt 

表格的方法,此特定菜单有两个子菜单,我可以制作子菜单但面临以下问题

1 -- 要在 MenuItem 中添加子菜单,我需要从不同的类/接口获取子菜单,我正在调用以下方法

pSubMenu = [CommonUIUtil GetCommonUIMenu:pSubMenu                                         
                                          ActionId:self                                   
                     Selector:@selector(MyMenuAction)];

该函数的原型如下

+(NSMenu *)GetCommonStatusMenu:(NSMenu *)pMenu ActionId:(NSObject*)aDelegate Selector:(SEL)selector

实现如下,

// pStrArray is Array of String to have the Menu Title 
    for(int idx =0;idx<[pStrArray count];idx++)
    {
        pTempStr = [pStrArray objectAtIndex:idx];
        pImage = [CommUIController CommonGetImage:[CommonUIUtil GetImageByStatus:pTempStr]];
        [pImage setSize:NSMakeSize(20,20)];
        pMenuItem =[[NSMenuItem alloc]init];
        [pMenuItem setTitle:pTempStr];

                // this should set the selector 
        [pMenuItem setAction:selector];
                // Setting the target 
        [pMenuItem setTarget:aDelegate];

        [pMenuItem setImage:pImage];
        [pMenuItem setEnabled:YES];
        [pMenu addItem:pMenuItem];
        [pMenuItem release];

        }
    return pMenu;

我可以在这个子菜单上看到图像,字符串,但我面临的问题是这个菜单根本没有启用,任何人都可以指导我,我在哪里犯了错误,

此函数将返回菜单和我将添加的菜单,如下所示,

pMenuItem = [pCTTableMenu itemWithTitle:@"Status"];
    //status menu is the menu returned from the above function,  
[pMainMenu setSubmenu:pStatusMenu forItem:pMenuItem];

提前致谢 :)

4

1 回答 1

0

看起来,我没有正确传递选择器方法,实际上我不知道如何在 Cocoa 中传递函数指针,可能我正在混合 Cocoa/Objective C 和 Normal C :),更正它,只是在方法中创建视图并在主类/接口中分配目标和操作

于 2011-01-27T05:52:36.370 回答