gpt4 book ai didi

cocoa - 从数据读取 :ofType:error: called before loading nib so I can't use my IBOutlets D:<

转载 作者:行者123 更新时间:2023-12-03 17:44:19 25 4
gpt4 key购买 nike

我有一个使用 NSDocument 打开文件的应用程序。我的 NIB 中有一个 NSView,我想根据打开的图像设置它的大小:

- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError {
NSLog("FOO");
// Load image
// ...

// Change size
[mainView setFrameSize:NSMakeRect(image.size.width, image.size.height)];
[mainView display]; // Redraw

[image release];
return YES;
}

但是,我做了一些 foobar 检查:“FOO”记录在 readFromData:ofType:error: 中,“BAR”记录在 View 的 initWithFrame: 方法中,但是控制台的输出是:

2010-10-30 16:20:45.670 Pwnshop[513:a0f] Foo
2010-10-30 16:20:45.680 Pwnshop[513:a0f] Bar

这意味着我正在向未启动的 NSView 发送 setFrameSize: 消息。

如何让 NSDocument 首先加载 Nib ,然后然后执行readFromData:ofType:error:,或者更好地之后更改 View 大小 Nib 已加载?

谢谢。

最佳答案

How can I make NSDocument load the nib first, and then do readFromData:ofType:error:, …

你不能。

从 2011 年开始编辑:但如果您需要 Snow Leopard 或更高版本,则可以覆盖 the canConcurrentlyReadDocumentsOfType: class method返回 YES,在这种情况下,您将在后台线程上收到 readFromData:ofType:error: 消息。阅读链接文档以了解相关要求和注意事项。

… or better change the view size after the nib is loaded?

实现windowControllerDidLoadNib:并在那里更改窗口/ View 。不要忘记调用 super,如 NSDocument-subclass 模板提供的实现所示。

关于cocoa - 从数据读取 :ofType:error: called before loading nib so I can't use my IBOutlets D:<,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4059110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com