3

我有一个包含两列的 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;
        }
...
}
4

2 回答 2

2

当您在大纲视图上调用 reloadData 时,大纲视图会删除其所有子视图(包括弹出框附加到的按钮)并重新创建它们。当按钮从其超级视图中移除时,弹出框将关闭。

您真的需要重新加载所有大纲视图数据吗?您能否使用 -reloadDataForRowIndexes:columnIndexes: 或 -reloadItem: 重新加载特定行?

或者,您可以尝试传递大纲视图本身,而不是将按钮(发送者)传递给 -showRelativeToRect:ofView:preferredEdge:m。

于 2013-07-26T09:58:18.567 回答
0

解决了。我将弹出框附加到 NSWindow 视图并使用 NSMouseLocation 作为弹出框的位置。

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];
于 2013-07-31T09:20:10.083 回答