- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个基于 NSDocument 的应用程序,运行良好 - 但现在我想给它一个客户 NSWindowController,以便我可以为其实现 NSTouchbar 支持。
到目前为止,我只是使用了 NSDocument 提供的标准 NSWindowController - 所以这不是我有任何经验的东西。我已经实现了 NSWindowController 的 stub ,我相信这应该足够了:
(文档.h)
#import <Cocoa/Cocoa.h>
@interface DocumentWindowController : NSWindowController
@end
@interface Document : NSDocument
.
.
.
(文档.m)
static NSTouchBarItemIdentifier WindowControllerLabelIdentifier = @"com.windowController.label";
@interface DocumentWindowController () <NSTouchBarDelegate>
@end
@implementation DocumentWindowController
- (void)windowDidLoad
{
[super windowDidLoad];
}
- (NSTouchBar *)makeTouchBar
{
NSTouchBar *bar = [[NSTouchBar alloc] init];
bar.delegate = self;
// Set the default ordering of items.
bar.defaultItemIdentifiers = @[WindowControllerLabelIdentifier, NSTouchBarItemIdentifierOtherItemsProxy];
return bar;
}
- (nullable NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier
{
if ([identifier isEqualToString:WindowControllerLabelIdentifier])
{
NSTextField *theLabel = [NSTextField labelWithString:@"Test Document"];
NSCustomTouchBarItem *customItemForLabel =
[[NSCustomTouchBarItem alloc] initWithIdentifier:WindowControllerLabelIdentifier];
customItemForLabel.view = theLabel;
// We want this label to always be visible no matter how many items are in the NSTouchBar instance.
customItemForLabel.visibilityPriority = NSTouchBarItemPriorityHigh;
return customItemForLabel;
}
return nil;
}
@end
@implementation Document
.
.
.
但现在我不知道如何连接它以便 NSDocument 使用我的 NSWindowController (DocumentWindowController)。我尝试在 xib 中创建一个新对象并将窗口连接到它 - 但这不起作用。我的 DocumentWindowController 方法都不起作用。我迷茫了!
帮助我 Stack Overflow,你是我唯一的希望!
最佳答案
来自How to Subclass NSWindowController
How to Subclass NSWindowController
Once you've decided to subclass NSWindowController, you need to change the default document-based app setup. First, add any Interface Builder outlets and actions for your document's user interface to the NSWindowController subclass instead of to the NSDocument subclass. The NSWindowController subclass instance should be the File’s Owner for the nib file because that creates better separation between the view-related logic and the model-related logic. Some menu actions can still be implemented in the NSDocument subclass. For example, Save and Revert Document are implemented by NSDocument, and you might add other menu actions of your own, such as an action for creating new views on a document.
Second, instead of overriding windowNibName in your NSDocument subclass, override makeWindowControllers. In makeWindowControllers, create at least one instance of your custom NSWindowController subclass and use addWindowController: to add it to the document. If your document always needs multiple controllers, create them all here. If a document can support multiple views but by default has one, create the controller for the default view here and provide user actions for creating other views.
You should not force the windows to be visible in makeWindowControllers. NSDocument does that for you if it’s appropriate.
关于objective-c - 如何为 NSDocument 实现自定义 NSWindowController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40614091/
我是一名优秀的程序员,十分优秀!