Why isn't my sheet attached to the window it's run for?

ぐ巨炮叔叔 提交于 2019-12-31 17:53:00

问题


I have a NIB which contains two windows, one is the app's main window visible at launch and the other is a custom sheet (and therefore not visible at launch). When the sheet is required my controller calls:

[NSApp beginSheet: sheetWindow modalForWindow: mainWindow modalDelegate: self didEndSelector: @selector(didEndSheet:returnCode:contextInfo:) contextInfo: nil];

which displays the sheet window and starts a modal session, but the window has a standard Aqua title bar, is not 'connected' to the main window and can be moved around just like a regular window. Needless to say, this is not desirable :-). Why doesn't the sheet window "pop out" of the window it's run for, as sheets usually do when begun in this fashion?

I had wondered whether the fact that I was beginning the sheet inside the controller's -awakeFromNib might have an effect, so I moved the sheet to a button's action I could trigger later. This didn't change the behaviour. I haven't thought of anything else to try. I'm targeting the 10.5 SDK, using Xcode 3.1.

Edit: so it looks like I've created a modal dialog; sheets and app-modal dialogs are both started with the -beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo: method. But how do I indicate that my window should be a sheet and not a modal dialog?


回答1:


If mainWindow is nil then the sheet will be displayed as a window/dialog.




回答2:


This happened to me a couple of days ago:

  • You forgot to set the window outlet of your window controller (File's owner of the Nib file). As Indicated by Nathan, you may see that the -[NSWindowController window] method returns nil.
  • You must also uncheck the Visible at launch option of the sheet.


来源:https://stackoverflow.com/questions/671204/why-isnt-my-sheet-attached-to-the-window-its-run-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!