我正在创建一个 IntelliSense 样式的弹出框,它向正在输入文本字段的用户显示什么语法是有效的。有谁知道如何在不给它焦点的情况下显示 NSPopover,以便用户可以继续输入文本字段?弹出框由 controlTextDidChange 触发:
- (void) controlTextDidChange:(NSNotification *)obj
{
NSTextField *field = [obj object];
NSString *command = [field stringValue];
if ([[command substringFromIndex: command.length - 1] isEqualToString: @"#"]){
CompletionMenuController *completionController = [[CompletionMenuController alloc] initWithNibName: @"CompletionMenuController" bundle:[NSBundle mainBundle]];
completionMenuPopover = [[NSPopoverInformation alloc] init];
[completionMenuPopover setContentViewController: completionController];
[completionMenuPopover setContentSize: completionController.view.frame.size];
[completionMenuPopover setBehavior: NSPopoverBehaviorTransient];
[completionMenuPopover setAppearance: NSPopoverAppearanceHUD];
[completionMenuPopover showRelativeToRect:[_commandBar frame] ofView:_commandBar preferredEdge:NSMaxYEdge];
}
}