Connecting file owner to app delegate

冷暖自知 提交于 2019-12-22 12:32:52

问题


At some point I deleted the Object to my appdelegate file for some reason from the XIB. I added a new object, and selected MyAppNameDelegate as the class. However, it's not connected to file owner, and I dont seem to get the option when right clicking and dragging. I think this is causing me some runtime issues. Any ideas?


回答1:


If you are referring to your MainMenu, the the file's owner is an object of type NSApplication.

In IB, you should select your file's owner, access it's 'delegate' outlet and drag it (as to draw a line) to your app delegate. This will restore the connection.

Check also that your file's owner has got the NSApplication class type. Maybe it got changed somehow.




回答2:


I had this same problem. I found a lot of half-answers on different threads, so I decided to put them together here.

  1. Drag an NSObject instance from the Objects palette to the area below "Objects" where the objects for your xib are listed (click on the triangle at the lower left if you can't see it) for MainWindow.xib. The object should show up as a solid orange box.
  2. Select this newly-created NSObject, and change its class to the name of your new App Delegate (whatever the file name is without the .h or .m), using the Identity Inspector. This should be an option in the pop-out list.
  3. Control-drag from the File's Owner to the new object, which should not be displayed as " App Delegate", and select delegate.
  4. You will also probably have to reconnect the Window (and possible other views) to your new delegate. Do this by dragging from the App Delegate to the Window and selecting window.

Hope this helps.




回答3:


This was driving me nuts also.

I marked +1 above, the answer does in fact help, the answer is cryptic, so this will help explain in finer detail how to get a delegate or another connection that won't link directly into the file using the "Assistant Editor" view.

right click = control key + left click.!

IN XCode 4. Select any of your XIB files. Say for a UIScrollView you added, you want to set the Delegate for it. Well unlike the prior IB where you just open up connections inspector, and drag a connection to the file. Its actually just the same here. BUT a difference.

(NOTE:The dock is panel 2 from the left. Only with a XIB open) Open up the Dock > http://developer.apple.com/LIBRARY/IOS/#documentation/ToolsLanguages/Conceptual/Xcode4UserGuide/InterfaceBuilder/InterfaceBuilder.html

There is a small triangle arrow there at the bottom of the Dock.

At the very top of the Dock is "Files Owner", without the dock opened, it is the white box with orange trim.

Select the view or what ever needs delegate access to the File (UISegmentControl drove me nuts on this too), right click and drag a connection on "New Referencing outlet" to the Docks "Files Owner", and a list will pop up.

Like wise, you can right click on the "Files Owner" and remove connections easily there, or make new ones.



来源:https://stackoverflow.com/questions/6170393/connecting-file-owner-to-app-delegate

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