objective-c – NSPopover – 当焦点丢失时隐藏? (在popover外点击)

前端之家收集整理的这篇文章主要介绍了objective-c – NSPopover – 当焦点丢失时隐藏? (在popover外点击)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用NSTableView的doubleClickAction来显示NSPopover.这样的事情
NSInteger selectedRow = [dataTableView clickedRow];
NSInteger selectedColumn = [dataTableView clickedColumn];


// If something was not selected,then we cannot display anything.
if(selectedRow < 0 || selectedColumn < 0)
{
    NSLog(@"Invalid selected (%ld,%ld)",selectedRow,selectedColumn);
    return;
} // End of something was not selected

// Setup our view controller,make sure if there was already a popover displayed,that we kill that one off first. Finally create and display our new popover.
DataInspectorViewController * controller =
[[DataInspectorViewController alloc] initWithNibName: @"DataInspectorViewController"
                                              bundle: nil];

if(nil != dataPreviewPopover)
{
    [dataPreviewPopover close];
} // End of popover was already visible

dataPreviewPopover = [[NSPopover alloc] init];
[dataPreviewPopover setContentSize:NSMakeSize(400.0f,400.0f)];
[dataPreviewPopover setContentViewController:controller];
[dataPreviewPopover setAnimates:YES];
[dataPreviewPopover showRelativeToRect: [dataTableView frameOfCellAtColumn: selectedColumn row: selectedRow]
                     ofView: dataTableView
              preferredEdge: NSMinYEdge];

哪个工作很好.我的popovers被创建并删除在我双击的单元格.问题是,如果我点击它之外的任何地方(如单击另一个单元格),我想让popover离开.我一直在环顾四周,但是对于我来说,我的生活无法弄清楚如何做到这一点.

这是我会认为是建立在一个popover,(我相当确定它是在iOS UIPopoverController类),所以我只是想知道如果我缺少一些简单的东西.

解决方法

我认为您需要更改您的popover(代码或界面构建器)中的属性行为
dataPreviewPopover.behavior = NSPopoverBehaviorTransient;

NSPopoverBehaviorTransient
The system will close the popover when the user interacts with a user interface element outside the popover.

在文档中阅读更多信息:
https://developer.apple.com/library/mac/#documentation/AppKit/Reference/NSPopover_Class/Reference/Reference.html

猜你在找的C&C++相关文章