1

I have not been able to get my NSPopover to detach to a window in my own projects, so to simplify I tried the Apple sample.

I downloaded a fresh copy of the Apple sample project: http://developer.apple.com/library/mac/samplecode/Popover/Introduction/Intro.html

It behaves the same, which is to say I can't drag the window to detach it either.

The project seems to provide all the correct windows and controllers and implements the detachableWindowForPopover: delegate method. However the method is never called.

Does anyone know the secret to detachable NSPopovers?

4

1 回答 1

6

在输入问题时找到了答案……</p>

Mac OS X 10.10 Yosemite 有一个新的委托方法:

  • (BOOL)popoverShouldDetach:(NSPopover *)popover

Yosemite 上的默认行为是 NO(不应分离)。因此,委托必须实现此方法才能使窗口可分离。示例项目没有实现此方法,因此在 Yosemite 上编译时它不会分离(并且还会产生几个弃用警告——也许我应该接受它需要更新的提示)。

添加:

- (BOOL)popoverShouldDetach:(NSPopover *)popover {
    return YES;
}

To MyWindowController.m 解决了这个问题。

于 2014-11-04T07:08:36.373 回答