I am trying to implement my own autocompletion system (the result is obtained from the sqlite database)
I installed NSTextField and the corresponding delegate. Each time the text in NSTextField changes, it calls the - (void)controlTextDidChange:(NSNotification *)aNotification
It works fine, in this method I build the menu programmatically, and finally I call / display it with this code:
NSRect frame = [address frame]; NSPoint menuOrigin = [[address superview] convertPoint:NSMakePoint(frame.origin.x, frame.origin.y+frame.size.height-25) toView:nil]; NSEvent *event = [NSEvent mouseEventWithType:NSLeftMouseDown location:menuOrigin modifierFlags:NSLeftMouseDownMask
Where address my NSTextField and menu is my NSMenu . The problem is that the menu is focused, so you can enter only one letter in the text box, and then you can no longer enter text, because now the menu is the first responder.
My questions are to show the menu and save the text field as the first responder so that you can enter it when the menu reloads every time the text in the field is changed.
This should be, for example, in the address bar of Safari or Chrome.
source share