I want to add the ability to use a date picker when editing a particular column in my table view, and used the code snippet from here, which worked well. However NSDatePicker
is not appropriate for my needs so I am using my own custom view, created using IB and loaded via a NSViewController
subclass to edit the date.
However I cannot figure out how to dismiss the pop-up menu in a way that accepts the edit, i.e. returns YES
in userAcceptedEdit
:
BOOL userAcceptedEdit = [menu popUpMenuPositioningItem:nil
atLocation:frame.origin
inView:tableView];
This was working fine when NSDatePicker
was the menu's view, but not with my custom view.
I am trapping the enter key actions from the text fields in my custom view, but all I can figure out is how to cancel the menu tracking which makes userAcceptedEdit == NO
:
MyCustomViewController.mm:
- (IBAction)textFieldAction:(id)sender {
logdbg(@"Action");
NSMenu* menu = [[self.view enclosingMenuItem] menu];
[menu cancelTracking];
}
The Views in Menu Items section of Apple's Application Menu and Pop-up List Programming Topics doesn't cover it either...
EDIT Here is a sample project, that demonstrates the issue.
Can someone provide some guidance please?