Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 352653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:45:26+00:00 2026-05-12T11:45:26+00:00

I am having a problem. My contextual menu is getting displayed but the menu

  • 0

I am having a problem. My contextual menu is getting displayed but the menu items are not activated.
so my new code for displaying the menu is as follows:

NSMenu *defMenu = [[[NSMenu alloc] initWithTitle:@"default Contextual Menu"] autorelease];

[defMenu insertItemWithTitle:@"Open" action:@selector(openFile) keyEquivalent:@"" atIndex:0];

[defMenu insertItemWithTitle:@"Delete" action:@selector(deleteFile) keyEquivalent:@"" atIndex:1];

return defMenu;

and function declaratons of deleteFile and openFile are as follows:

-(int)openFile;

-(int)deleteFile;

and i am calling my contextual menu as follows:

-(void)doSingleClick 
{

    if([[NSApp currentEvent] modifierFlags] & NSControlKeyMask)
    {

        NSLog(@"control clicked.......");

        [NSMenu popUpContextMenu:[self defaultMenu] withEvent:[NSApp currentEvent] forView:tableView];

        return;
    }

}

my contextual menu items are all shaded and cannot be clicked. Please can you tell where i am going wrong.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T11:45:26+00:00Added an answer on May 12, 2026 at 11:45 am

    Your openFile: method takes an int as a parameter. Since insertItemWithTitle:action:withObject:keyEquivalent:atIndex: takes an object, the selector you give it must also take an object.

    You can use NSNumber to wrap your int as an object, and simply change your openFile: method to take an NSNumber rather than an int. Like so:

    [defMenu insertItemWithTitle:@"Open" action:@selector(openFile:) withObject:[NSNumber numberWithInt:5] keyEquivalent:@"" atIndex:0];
    
    - (void)openFile:(NSNumber *)fileNumber {
        int rowClicked = [fileNumber intValue];
        // Do whatever your old method did here
    }
    

    EDIT: To answer your updated question:

    The reason your menu items are disabled is that you’ve only told them what method name to call. You never told the items on which object instance those methods should actually be called. To fix this, you need to set the items’ target:

    NSMenuItem *openItem = [defMenu insertItemWithTitle:@"Open" action:@selector(openFile:) withObject:[NSNumber numberWithInt:5] keyEquivalent:@"" atIndex:0];
    [openItem setTarget:self];
    

    And so forth for each item you’ve got.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a problem that is strange to me but hopefully is not
Having problem with the middle Div not expanding to the width http://acs.graphicsmayhem.com/images/middiv.jpg Ok, how
I am having problem in getting reference of Ajax control extender using $find() or
Having problem with this bit of code qith jQuery. it should pick the values
i having problem in converting this C# code into VB.net. The loadLecturer seem to
Having problem to open form in new window, script is pulled from external service.
i having problem understanding what is wrong with my inheritance. I just can not
Having problem in IE8 with vertical align for images not working when a table
Im having problem's adding map markers to gmaps using jquery. Here is my code
Having problem in displaying relational properties b/w two tables having one(company) to many(package_master) relationship

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.