开发者

AppDelegate file missing in Xcode 3.1?

i am currently starting to learn Xcod开发者_Python百科e and objective-c and i am reading three different books on that topic currently. All of these books refer to a file called "AppDelegate" (My_First_ProjectAppDelegate.m, My_First_ProjectAppDelegate.h) which are said to be "created with the Project" (i am creating a "Cocoa Application"). These files are not present when I create a new Project. I seem to be not the only one having this problem (see http://pragprog.com/titles/dscpq/errata ).

Is there any more information about AppDelegate? What is the current practice on how to deal with a missing Appdelegate? i am using Xcode Version 3.1.4 on Mac OSX Leopard.


AppDelegate is nothing more than a common NSObject class with needed connections in MainMenu.xib. You can easily recreate your own:

  1. Create a class, name it AppDelegate
  2. Open MainMenu.xib and add NSObject object to object palette
  3. In object inspector's Identity tab (the last one) set object's class to AppDelegate (you should get autocomplete)
  4. Ctrl+drag from Application object to your newly created AppDelegate object and choose "delegate" from opened panel.


As I recall, only the iPhone templates were providing delegate classes by default. This is not a huge deal, but I can see how you would be concerned if you are just learning. Are you sure what you are reading is relevant to MacOS applications and not Iphone?

You can always create your own delegate class manually. You just create a class as you normally do, then set it as the delegate for NSApplication in Interface Builder.


I think the confusion comes from the version of XCode you are using.

Xcode version 3.2 changed the default behavior when you create a new project: it now creates an AppDelegate for your project. I can't remember what the earlier versions did, but it was different.

As Eimantas says, if you want to use an AppDelegate then you can just create one following the steps he describes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜