Question

I need to create a Menu for a selected row of a table, I am able to create by overriding

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

Method, of a table, This particular Menu has two sub-menu, i am able to make the Sub-Menu but facing Following Problem

1 -- To Add a Sub-Menu in a MenuItem, i need to get Sub-Menu from a different class/Interface, i am calling following method

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

Where prototype of this function is as follow

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

Implementation as below,

// 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;

I am able to see the Image, String on this Sub Menu, but the problem i am facing is this menu is not at all Enable, can anyone guide me , where i am making the mistake,

This function will return the Menu and Menu i will add as below,

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

Thanks in Advance :)

Was it helpful?

Solution

looks like, i am not passing the selector method properly, in fact i don't know how to pass function pointer in Cocoa, probably i am mixing Cocoa/Objective C and Normal C both :), corrected, it, in the method just creating the view and in the main class/interface assigning target and action

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top