我有一个包含两列的 NSOutlineView(基于视图)。在第二列中,我有一个 NSButton 连接到一个 NSPopOver。
当我单击按钮时,它会按预期显示 NSPopOver => Popover 可见。
问题: 如果我重新加载 NSOutlineView 的数据,它会隐藏 NSPopover !
这是正常行为吗?如何避免这种情况?
换句话说,popoverWillClose 委托消息在每次 reloadData 之后被调用
//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;
}
...
}