Connect Window Controller Outlet to Window

假如想象 提交于 2020-01-31 05:32:06

问题


I am trying to create a simple modal dialog in XCode 4. I have created the xib, created the NSWindowController derived class and made it the class in the File's Owner of the xib. The part I am having trouble with is physically connecting the window outlet as mentioned in the answers to questions:

How to give focus to NSWindow loaded from NIB?

Why do I have to call showWindow on my NSWindowController twice on 10.5?

and in Apple documentation here:

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Documents/Concepts/WinControllersAndNibs.html

I understand the concept, but I cannot figure out how to actually do it in XCode 4! I know how to connect a control in a xib to an outlet or action in a class via CTRL-drag. I just do not know what to drag to and from in this case.

Any help appreciated.


回答1:


OK - I figured it out.

window outlet: In the IB Dock, select the File's Owner object. Control-drag from there to the window in the XIB file. That will create the new Outlet.

delegate outlet: To connect the delegate outlet to the File's Owner, select the Window in the IB Dock. In the connection inspector, under Outlets, control-drag from "delegate" to "File's Owner" This connection can also be made with the File's Owner selected, just control-drag from Referencing Outlets to the window and select "delegate" from the popup.

Edit: The best way to get this effect, delegate-to-File's Owner outlet in Window and window-to-Window outlet in File's Owner, is to create the NSWindowController-derived class first and let XCode create the xib in the process. Both outlets will be automatically created.

If the xib was created first, and you wish to hook it to a NSWindowController-derived class, then the outlets can be created via ctrl-drag in IB:

  • To create the window-to-Window outlet in File's Owner, select File's Owner and ctrl-drag from File's Owner to Window, then select "window" in the popup.
  • To create the delegate-to-File's Owner outlet in Window, select Window and
    • Ctrl-drag from Window to File's Owner, then select "delegate" in the popup.
    • or then select Connections Inspector and ctrl-drag from delegate to File's Owner.

These steps can also be "inverted" by using New Referencing Outlet....



来源:https://stackoverflow.com/questions/9088339/connect-window-controller-outlet-to-window

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