Question

I am using an NSTableView which is connected to a NSMenu in IB.

Now I can right click a selected cell and choose the context menu for the selected item.

This is all fine, however, the TableView can show context menu for items which are not selected:

enter image description here

So now the action applies to the selected item in the list, rather than item that was actually right-clicked: I want to open 6 but eventually 1 is opened in the browser.

This is how I handle the click Event:

- (IBAction)openInBrowserClicked:(id)sender {

    Issue *i = self.issuesController.selectedObjects.lastObject;
    [[NSWorkspace sharedWorkspace] openURL:i.URL];
}
Was it helpful?

Solution

You can use the table views clickedRow property/method to determine on which row the click was placed. Next get from your data source the object for the clicked row and that is it.

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