How Window Controllers Work

本文深入探讨了NSWindowController的工作原理,包括其在加载与显示窗口、定制窗口标题、存储窗口框架等方面的作用。此外,还讨论了它在文档基础架构中的角色,以及如何根据需求创建自定义子类。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

How Window Controllers Work

controller object (in this case, NSWindowController) manages a window; this object is usually stored in a nib file. This management entails the following:

  • 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 NSDocumentsubclass) and, in turn, keeps a reference to the document. For a discussion of this architecture, seeDocument-Based Applications Overview.

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.

For simple documents—that is, documents with only one nib file containing a window—you need do little directly with NSWindowController objects. 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 ofNSWindowController (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 object or separately created and configured NSWindowController objects are used.

Window Closing Behavior

When a window is closed and it is part of a document-based application, the document removes the window’s window controller from its list of window controllers. This results in the deallocation of the window controller and the window, and possibly the deallocation of the NSDocument object itself. When a window controller is not part of a document-based application, closing the window does not by default result in the deallocation of the window or window controller. This is the desired behavior for a window controller that manages something like an inspector; you shouldn’t have to load the nib file again and re-create the objects the next time the user requests the inspector.

If you want the closing of a window to make both window and window controller go away when it isn’t part of a document, your subclass of NSWindowController can observe NSWindowWillCloseNotification or, as the window delegate, implement the windowWillClose: method and include the following line of code in your implementation:

[self autorelease];

As a consequence of autoreleasing itself, an NSWindowController object autoreleases its window as well as all other top-level objects in its nib file. In any case, a window controller should not get rid of its window until it ensures its own deallocation.

### Kubernetes 控制平面污点未找到问题分析 当遇到 `taint "node-role.kubernetes.io/control-plane" not found` 的提示时,这通常意味着集群中的控制节点上不存在预期的污点设置[^1]。此情况可能发生在多种场景下: - 集群初始化过程中出现问题 - 节点配置被意外修改或删除 - 使用了不同版本间的不兼容操作 对于 “No controllers found” 错误,虽然直接关联的信息较少,但从Kubernetes架构角度出发,可以推测该问题是由于API Server未能成功调度控制器管理器到任何具有适当标签和容忍度(Toleration)的工作节点所致。 #### 解决方案建议 为了恢复正常的集群状态并确保控制器能够正常工作,可采取以下措施: 1. **验证现有节点的状态** 检查当前集群内所有节点及其属性,特别是关注是否有标记为master或control-plane的角色存在。 ```bash kubectl get nodes -o wide ``` 2. **重新应用必要的污点** 如果发现确实缺失了特定于控制面节点的污点,则可以通过命令行手动添加回去: ```bash kubectl taint nodes <your-control-plane-node> node-role.kubernetes.io/control-plane=:NoSchedule ``` 3. **确认组件健康状况** 查看各个核心组件如 API server, controller manager 和 scheduler 是否处于Running状态,并监听正确的端口和服务地址。 ```bash kubectl get componentstatuses ``` 4. **检查日志记录** 对涉及的关键服务进行深入的日志审查,寻找可能导致控制器实例启动失败的具体原因。 ```bash kubectl logs -n kube-system $(kubectl get pods -n kube-system | grep kube-controller-manager | awk '{print $1}') ``` 通过上述方法应该可以帮助定位并修复“No controllers found”的根本原因,从而恢复正常的服务功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值