子窗口未正确添加
我正在尝试在 OS X 应用程序中的主窗口底部添加一个辅助窗口,希望最终能够实现它,以便在按下切换按钮时它会从窗口下方动画出来。据我所知,使用 SDK 执行此操作的最佳方法是使用 - [NSWindow addChildWindow:ordered:]
添加窗口作为子窗口。但是,当我调用该函数时,尽管显示了辅助窗口,但它并未添加为子窗口。这是我按下按钮时调用的函数:(
- (IBAction)childToggleButtonPressed:(id)sender {
[self.window addChildWindow:_secondaryWindowController.window ordered:NSWindowBelow];
NSLog(@"Child Windows: %@", [[self.window childWindows] count]);
}
我还没有添加代码来关闭它,因为我要确保它首先出现。)
这是控制台的输出:
2011-08-31 12:37:25.312 Playground[1712:707] Child Windows: (null)
有谁知道为什么该窗口没有被添加为子窗口,我能做些什么来解决这个问题?
一些可能有帮助的附加上下文是我正在使用图像作为窗口本身和标题栏的背景来绘制自定义窗口。我正在修改的代码可以在 http 找到://cocoawithlove.com/2008/12/drawing-custom-window-on-mac-os-x.html。
谢谢你!
编辑: 我尝试覆盖 - [NSWindow addChildWindow:ordered:]
函数并记录我能找到的任何信息,结果发现窗口本身并未传递给功能。希望这能帮助有人找出问题!
I'm trying to add a secondary window to bottom of my main window in an OS X application, with the hopes of eventually making it so it animates out from underneath the window when a toggle button is pressed. As far as I can tell, the best way to do this with the SDK is to add a window as a child window using - [NSWindow addChildWindow:ordered:]
. However, when I call that function, although the secondary window is displayed, it isn't added as a child window. Here's the function called when I press the button:
- (IBAction)childToggleButtonPressed:(id)sender {
[self.window addChildWindow:_secondaryWindowController.window ordered:NSWindowBelow];
NSLog(@"Child Windows: %@", [[self.window childWindows] count]);
}
(I haven't added the code to dismiss it yet because I'm making sure it shows up in the first place first.)
And here's the output to the console:
2011-08-31 12:37:25.312 Playground[1712:707] Child Windows: (null)
Does anyone know why the window isn't being added as a child and what I can do to fix this?
Some additional context that might help is that I'm drawing a custom window using an image as the background for both the window itself and the title bar. The code I'm modifying can be found at http://cocoawithlove.com/2008/12/drawing-custom-window-on-mac-os-x.html.
Thank you!
EDIT: I tried overriding the - [NSWindow addChildWindow:ordered:]
function and logging any information I could find, and it turns out the window itself isn't passed to the function. Hopefully this will help someone find out the problem!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终通过使子窗口没有 NSWindowControllers 来解决这个问题。显然你不能将 NSWindowController 的窗口指定为子窗口。一旦我将它们变成 NSWindow 子类,我就可以使用上面显示的代码将它们添加为子窗口(当然,用窗口替换 _secondaryWindowController.window )。
简而言之,不要使用 NSWindowController 的窗口作为子窗口,而只使用 NSWindow。
I ended up solving this problem by making it so that the child windows did not have NSWindowControllers. Apparently you can't assign the window of an NSWindowController to be a child window. As soon as I turned them into NSWindow subclasses, I could add them as child windows using the code I showed above (replacing _secondaryWindowController.window with the window, of course).
In short, don't use an NSWindowController's window as a child window, use just an NSWindow.