为什么苹果的示例代码项目 IKImageViewDemo 没有 AppDelegate 类? [英] Why Apple's sample code project IKImageViewDemo does not have an AppDelegate class?

查看:52
本文介绍了为什么苹果的示例代码项目 IKImageViewDemo 没有 AppDelegate 类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究如何在我的应用中使用 IKImageView.我从 Apple 网站下载了以下演示.

I have studying how to use IKImageView in my app. I downloaded the following demo from Apple site.

https://developer.apple.com/library/mac/samplecode/IKImageViewDemo/Introduction/Intro.html#//apple_ref/doc/uid/DTS10004049

我不明白的一件事是:这个项目只实现了一个控制器类.

One thing I do not understand is: This project has only implemented a Controller class.

@interface Controller : NSObject
{ 
 ...

我完全不明白它是如何工作的.如果我在 XCode 中创建一个新项目,它通常会生成一个实现 NSApplicationDelegate 接口的 AppDelegate 类.

I do not understand how does it work at all. If I create a new project in XCode, it will usually generate an AppDelegate class which implements NSApplicationDelegate interface.

我不知道我是否正确理解了这个机制.

I do not know if I understand the mechanism correctly.

以下步骤是否描述了它的工作原理?

Does the following steps describe how it works?

1) 在 info.plist 中,它指定主包是 MainMenu.xib.

1) In info.plist it specifies the main bundle is MainMenu.xib.

2) Window 像这样绑定到 Controller

2) the Window is binded to the Controller like so

3) 当应用程序启动时,它从 MainMenu.xib 加载 Windows 并且 Controller 类从

3) When the application starts, it loads the Windows from the MainMenu.xib and the Controller class takes over the windows interaction from there.

推荐答案

这真的是很老的示例代码.它早于为您生成应用程序委托的 Xcode 项目模板.那时,早期的 Xcode 和 ProjectBuilder(它的旧名称)交给你来做.

It's really old sample code. It predates Xcode project templates generating an app delegate for you. Back then, early Xcode and ProjectBuilder (the old name for it) Left it up to you to do that.

许多较旧的示例代码都有这种东西.只要事情通过nib加载启动,魔法就会发生,对象被实例化并连接

Lots of older sample code has this sort of thing. As long as things get kickstarted by nib loading, magic happens, objects are instantiated and connected

如果你有一个继承自 NSObject 的简单控制器,并且它在你的主 nib 文件中有一个代理,它将被创建.如果您还将其代理作为委托连接到笔尖中的某个视图或控件,所有这些都会发生.

If you have a simple controller that inherits from NSObject and it has a proxy in you main nib file, it will get created. If you also connect its proxy as delegate to some view or control in the nib, all of that happens.

从技术上讲,您不需要作为 NSApplication 对象委托的对象.但实际上这是一个很好的最佳实践,任何非平凡的应用程序都将拥有这一点以及更多.

You don't technically need an object that is the delegate of you NSApplication object. But in reality it is a good best practice and any non trivial app will have that and a lot more.

当您的应用程序启动时调用 C 函数 NSApplicationMain() 时,会发生很多神奇的事情.

There's a lot of magic that happens when the C function NSApplicationMain() is called at the launch of your app.

如果日期簿 Cocoa in a Nutshell 很好地涵盖了这一点,那么旧的并且在很多方面都过时了.

The old and in many ways out if date book Cocoa in a Nutshell covers this well.

这篇关于为什么苹果的示例代码项目 IKImageViewDemo 没有 AppDelegate 类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆