0

(注:问题之前已经提出过,一年多前的结果还没有定论。希望我们现在知道更多并且可以解决它?)

双击时,我试图在 NSCollectionItem 上显示 NSPopover。我的 NSCollectionView 设置正确并接收输入。

(如果我将代码复制粘贴到其他 NSView 子类,它工作得很好。NSCollectionView 有一些东西似乎把事情搞砸了。)

编码:

BIECollectionViewItem.h

#import <Cocoa/Cocoa.h>

@class BIEAppDelegate;

@interface BIECollectionViewItem : NSView {
    IBOutlet NSPopover *popover;
}

@end

BIECollectionViewItem.m

#import "BIECollectionViewItem.h"

@implementation BIECollectionViewItem

- (id)initWithFrame:(NSRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code here.
    }

    return self;
}

- (void)drawRect:(NSRect)dirtyRect
{
    // Drawing code here.
}

- (void)mouseDown:(NSEvent *)theEvent {
    [super mouseDown: theEvent];
    if([theEvent clickCount] == 2){
        [popover showRelativeToRect: [self bounds] ofView: self preferredEdge: NSMaxYEdge];
    }
}

@end

如果我在 mouseDown 事件中添加一条日志语句,我可以确认该事件正在被触发。但是,NSPopover 拒绝出现!

有谁知道如何让 NSPopover 出现在 NSCollectionView 上?

4

1 回答 1

0

Not sure if you have solved this problem, but I have done this before. I recently wanted to display a NSPopOver relative to a NSTextField in a NSCollectionViewItem. I have had no trouble, except at one point I was getting the relativeToRect: parameter wrong, and the pop over wouldn't show. I always use this same format when displaying a pop over

NSView *someView; // defined elsewhere
[MyPopOver showRelativeToRect:[someView bounds] ofView:someView preferredEdge:NSMaxXEdge];

I can only suggest ensuring you have those values right, and you haven't made some silly mistake in IB like forgotten a binding or connection (90% of my failures).

Hope this helps with your problem

于 2012-09-04T05:44:06.163 回答