我有一个带有两列的NSOutlineView(基于视图)。在第二列中,我有一个NSButton连接到一个NSPopOver。
当我点击按钮时,它会显示NSPopOver符合预期=> Popover是可见的。
问题:如果我重新加载NSOutlineView的数据,它会隐藏NSPopover!
这是正常行为吗?怎么避免这个?
换句话说,在每次reloadData
之后调用popoverWillClose委托消息//OMN_Object.m
#pragma mark - Actions
- (IBAction)togglePopover:(id)sender
{
...
Call App_delegate togglePopover:withTextLog:withTextInputFileDetails:withTextOutputFileDetails:fromObject:
//App_delegate.m
...
[self.myPopOver setDelegate:self];
...
#pragma mark Popover delegate
- (void)popoverWillClose:(NSNotification *)notification
{
NSLog(@"%s *** popoverWillClose %@",__PRETTY_FUNCTION__, self.myPopOver);
}
-(void)togglePopover:(id)sender withTextLog:(NSString*)textLog
withTextInputFileDetails:(NSString*) textInfoInput
withTextOutputFileDetails:(NSString*) textInfoOutput
fromObject:(id)object
{
id v = [[self.myPopOver contentViewController] view] ;
NSTextView *t1 = [v textViewLog];
[t1 setString:textLog];
NSTextView *t2 = [v textViewInputFileDetails];
[t2 setString:textInfoInput];
NSTextView *t3 = [v textViewOutputFileDetailsLastPassFileOnly];
[t3 setString:textInfoOutput];
if (self.myPopOver.isShown == 0) {
NSLog(@"%s Displaying popover %@", __PRETTY_FUNCTION__, self.myPopOver);
[self.myPopOver showRelativeToRect:[sender bounds]
ofView:sender
preferredEdge:NSMaxYEdge];
self.objectOwnerOfPopOver = object;
}
else {
NSLog(@"%s Closing popover %@", __PRETTY_FUNCTION__, self.myPopOver);
[self.myPopOver close];
self.objectOwnerOfPopOver = nil;
}
}
// Outline_view_delegate.m
- (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item{
...
else if ([[tableColumn identifier] isEqualToString:@"Status"]){
if ([item isKindOfClass:[OMN_Object class]])
{
OMN_Object *o = item;
ObjectStatusTableCellView *v = [outlineView makeViewWithIdentifier:@"StatusCell" owner:self];
....
[v.buttonRevealInFinder setAction:@selector(buttonRevealInFinderClicked:)];
[v.buttonRevealInFinder setTarget:o];
[v.buttonInfo setTarget:o];
[v.buttonInfo setAction:@selector(togglePopover:)];
return v;
}
...
}
答案 0 :(得分:2)
在大纲视图上调用reloadData时,大纲视图会删除其所有子视图(包括弹出框附加到的按钮)并重新创建它们。当从超级视图中删除该按钮时,弹出窗口将被关闭。
您真的需要重新加载所有大纲视图数据吗?你可以使用-reloadDataForRowIndexes:columnIndexes:或-reloadItem重新加载特定的行:?
或者,不是将按钮(发送者)传递给-showRelativeToRect:ofView:preferredEdge:m,您可以尝试传递大纲视图本身。
答案 1 :(得分:0)
解决。我将popover附加到NSWindow视图,并将NSMouseLocation用于popover的位置。
NSPoint mouseLoc2 = [self.window mouseLocationOutsideOfEventStream];
NSRect r4 = NSMakeRect(mouseLoc2.x -10, mouseLoc2.y -10, 16, 16);
[self.myPopOver showRelativeToRect:r4
ofView:self.window.contentView
preferredEdge:NSMaxYEdge];