我真的希望我能更具体,但不幸的是,我不能。所有合适的对象都是非空的,并且所有合适的方法调用(可能)都是成功的,但是我的NSPopover从来没有出现过。委托方法也不会被调用。
// ivars
NSPopover *tagPopover;
NSViewController *tagPopoverViewController;
// in method to display popover
tagPopover = [[NSPopover alloc] init];
[tagPopover setBehavior: NSPopoverBehaviorApplicationDefined];
[tagPopover setDelegate: self];
tagPopoverViewController = [[MYViewController alloc] initWithNibName: @"MYViewController" bundle: nil];
[tagPopover setContentViewController: tagPopoverViewController];
[tagPopover setContentSize: tagPopoverViewController.view.frame.size];
[tagPopover showRelativeToRect: NSMakeRect(700, 400, 5, 5) // Screen coordinates
ofView: [[NSApp keyWindow] contentView]
preferredEdge: NSMinYEdge];发布于 2012-07-16 06:48:47
事实证明坐标系是错误的:
NSRect theRect = [[NSApp keyWindow] convertRectFromScreen: NSMakeRect(700, 400, 5, 5)];
[tagPopover showRelativeToRect: theRect // Window Coordinates
ofView: [[NSApp keyWindow] contentView]
preferredEdge: NSMinYEdge];需要先将其转换为窗口的坐标系。
发布于 2012-07-16 03:56:21
我怀疑tagPopoverViewController.view.frame是NSZeroRect,因为frames是在它们开始出现在屏幕之前设置的(例如,它们从xibs/故事板出来是没有意义的)。你确定你需要那条线吗?文档提到,contentSize无论如何都要绑定到内容视图的大小。
https://stackoverflow.com/questions/11495082
复制相似问题