0

(Note: question has been asked before, with less-than-conclusive results over a year ago. Hopefully we know a bit more now and can solve it?)

I'm trying to make an NSPopover display over an NSCollectionItem when it is double-clicked. My NSCollectionView is set up properly and receives input.

(If I copy-paste the code to other NSView subclasses, it works just fine. There is something with NSCollectionView that appears to be messing things up.)

The code:

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

If I add a log statement in the mouseDown event, I can confirm that the event is being fired. However, the NSPopover refuses to appear!

Does anyone know how to get an NSPopover to appear over an NSCollectionView?

Community
  • 1
  • 1
  • Where do you `alloc` and `init` `NSPopover`? – trojanfoe Jul 18 '12 at 07:00
  • I'm not; Interface Builder is handling that for me. I just dragged an `NSPopover` from the IB Library. It then automatically created an `NSPopover` object, an `NSViewController` (labeled "Popover View Controller"), and an `NSView`, which contains the interface items that I want to appear in the popover. I've tested it in the main window, and it all works, but when I put it to the `NSCollectionView`, it fails to appear. – Jonathan Stoler Jul 18 '12 at 21:51

1 Answers1

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

Steffan
  • 200
  • 5