Mac OS AppKit文档翻译——NSWindowController

NSWindowController

 An NSWindowController object manages a window, usually a window stored in a nib file.

一个NSWindowController对象管理一个窗口,通常这个窗口存储在nib文件中。


Overview

This management entails:

管理限制:

——Loading and displaying the window

加载并显示窗口

——Closing the window when appropriate

在适当的时候关闭窗口

——Customizing the window s title

自定义窗口的标题

——Storing the window s frame (size and location)  in the defaults database

存储窗口的大小(包括坐标和长宽)在默认的数据库里

——Cascading the window in relation to other document windows of the application

叠加应用中相关的其它文档窗口


A window controller can manage a window by itself or as a role player in the Application Kit‘s document-based architecture, which also includes NSDocument and NSDocumentController objects. In this architecture, a window controller is created and managed by a "document" (an instance of an NSDocument subclass) and, in turn,  keeps a reference to the document.

一个窗口控制器管理自身的一个窗口,或者在Application Kit基于文档的结构中起到一定作用,窗口控制器也包含NSDocument类和NSDocumentController类。在这样一种结构里,创建一个窗口控制器,并通过一个‘文档’(它是NSDocument子类的一个实例)来管理,让它和文档保持关连性。

The relationship between a window controller and a nib file is important. Although a window controller can manage a programmatically created window  it usually manages a window in a nib file. The nib file can contain other top-level objects, including other windows, but the window controller‘s responsibility is this primary window. The window controller is usually the owner of the nib file, even when it is part of a document-based application. Regardless of who is the file’s owner  the window controller is responsible for freeing all top- level objects in the nib file it loads.

窗口控制器与nib文件之间的有着很重要的关系。窗口控制器从程序上来讲,虽然能管理被创建的窗口,但它通常是管理nib文件里的这个窗口。这个nib文件可以包含其它高级对象,包括其它窗口,但是窗口控制器的职责是负责当前的窗口。这个窗口控制器通常是nib文件的拥有者,它也是一个基于文件的应用的一部分。暂不管这个文件到底属于谁,窗口控制器主要负责释放nib文件加载的所有高级对象。

For simple documents—that is, documents with only one nib file containing a window—you need do little directly with NSWindowController. The Application Kit will create one for you. However, if the default window controller is not sufficient, you can create a custom subclass of NSWindowController. For documents with multiple windows or panels, your document must create separate instances of NSWindowController (or of custom subclasses of NSWindowController), one for each window or panel. An example is a CAD application that has different windows for side  top  and front views of drawn objects. What you do in your NSDocument subclass determines whether the default NSWindowController or separately created and configured NSWindowController objects are used.

对于一个简单的文档——即一个带窗口的nib文件——你不需要直接做任何与 NSWindowController 相关的事情, Application Kit包会自为你创建一个窗口控制器。但是,如果默认的窗口控制器不够用的话,你可以创建一个自定义的 NSWindowController 的子类。当文件带有多个窗口或面板时,必须单独创建 NSWindowController 的实例,每一个实例对应一个窗口或一个面板。例如CAD这个软件,它有不同的窗口,位于边上的,顶部的,可以拖拽的,以及前端视图等。你在 NSDocument 子类里的操作决定了是使用默认的 NSWindowController 对象,还是使用单独创建配置的 NSWindowController 对象。


Subclassing NSWindowController

You should create a subclass of NSWindowController when you want to augment the default behavior, such as to give the window a custom title or to perform some setup tasks before the window is loaded. In your class‘s initialization method  be sure to invoke on super either one of the initWithWindowNibName:... initializers or the initWithWindow: initializer. Which one depends on whether the window object originates in a nib file or is programmatically created.

当需要修改默认的参数动作时,可以创建一个 NSWindowController 的子类,例如,在窗口加载之前,自定义窗口的标题,修改一些启动任务。在自定义的类的初始化方法里,首先要确定调用了父类的方法,或者使用了“initWithWindowNibName: ”或 “initWithWindow: ”等初始化方法。具体采用哪一种方法,取决于这个窗口对象是来自nib文件还是来自代码创建的。

《明日此时》历时一年,这是我翻译的小说,后续时间充裕的话,也会继续给大家翻译技术文档的哦~握爪嘤

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,277评论 6 503
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,689评论 3 393
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 163,624评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,356评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,402评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,292评论 1 301
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,135评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,992评论 0 275
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,429评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,636评论 3 334
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,785评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,492评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,092评论 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,723评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,858评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,891评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,713评论 2 354

推荐阅读更多精彩内容