Close NSTokenField completion list when clicking an item?

I have an NSTokenField in my application. When I click on one of the sentences from the completion list, I would like the list to disappear and the token to be completed (for example, Mail). However, this does not seem to be happening - clicking a sentence simply adds the rest of the line and the list does not disappear.

The completion list disappears if I press Return, but I want it to be fired by clicking on the hint. How can i achieve this?

+5
source share
2 answers

I found a solution to this problem, which is not yet ideal, but I hope that it will soon solve the last issue that I have.

rubymotion, Objective-C Ruby, , Ruby. , Objective-C.

NSTokenField controlTextDidChange NSControl, , . , NSLeftMouseUp, , , Return ( fooobar.com/questions/390846/...). .

Ruby:

def controlTextDidChange(aNotification)
  application = NSApplication.sharedApplication
  event = application.currentEvent
  if event.type == NSLeftMouseUp
    e1 = CGEventCreateKeyboardEvent(nil, 0x24, true)
    CGEventPost(KCGSessionEventTap, e1)
  end
end

, , : , , , , . , , , , .

, , , !

, . tokenField:completionsForSubstring:indexOfToken:indexOfSelectedItem::

selectedIndex[0] = -1
+4

@ siekfried!

- (void)controlTextDidChange:(NSNotification *)aNotification;
{
    if([[NSApplication sharedApplication]currentEvent].type == NSLeftMouseUp)
    {
        CGEventPost(kCGSessionEventTap, CGEventCreateKeyboardEvent(nil, 0x24, true));
    }
}

;)

, :

-(NSArray *)tokenField:(NSTokenField *)tokenField completionsForSubstring:(NSString *)substring indexOfToken:(NSInteger)tokenIndex indexOfSelectedItem:(NSInteger *)selectedIndex
{
    *selectedIndex = -1;
...
...
}
0

All Articles