需要帮助来解决窗口打开问题

时间:2022-11-24 21:23:34

I followed the Tutorial in Cocoa Programming For Mac OS X to create a preferences window but am returned with 2 warnings which stop it from working/opening. These are the two warrnings: alt text http://snapplr.com/snap/varq

我按照Cocoa编程中的教程为Mac OS X创建了一个首选项窗口,但是返回了2个警告,使其无法工作/打开。这些是两个版本:alt文本http://snapplr.com/snap/varq

alt text http://snapplr.com/snap/qmxc

替代文字http://snapplr.com/snap/qmxc

How can I resolve the problem?

我该如何解决这个问题?

2 个解决方案

#1


The warnings mean the object in question doesn't (as far as the compiler knows) implement those two methods. This means either your window controller is not inheriting from the right superclass, or the pointer to the window controller is of the wrong type. It may or may not be the reason your window isn't opening, it's impossible to tell from the warnings alone.

警告意味着有问题的对象没有(就编译器所知)实现这两种方法。这意味着您的窗口控制器不是从正确的超类继承,或者指向窗口控制器的指针是错误的类型。它可能是也可能不是你的窗户没有打开的原因,单凭警告是不可能的。

edit: from your full code it looks like you're declaring your controller as inheriting from NSObject, instead of NSWindowController.

编辑:从您的完整代码看起来您​​声明您的控制器继承自NSObject,而不是NSWindowController。

#2


Just as it says, showWindow isn't defined on the PreferenceController class. In C++, this would be an error because it's statically typed and would say "method not defined", but since Objective-C is more flexible, this is only a warning. Without seeing the code, it's hard to tell what your mistake is though.

正如它所说,showWindow没有在PreferenceController类上定义。在C ++中,这将是一个错误,因为它是静态类型的并且会说“方法未定义”,但由于Objective-C更灵活,这只是一个警告。没有看到代码,很难说出你的错误是什么。

#1


The warnings mean the object in question doesn't (as far as the compiler knows) implement those two methods. This means either your window controller is not inheriting from the right superclass, or the pointer to the window controller is of the wrong type. It may or may not be the reason your window isn't opening, it's impossible to tell from the warnings alone.

警告意味着有问题的对象没有(就编译器所知)实现这两种方法。这意味着您的窗口控制器不是从正确的超类继承,或者指向窗口控制器的指针是错误的类型。它可能是也可能不是你的窗户没有打开的原因,单凭警告是不可能的。

edit: from your full code it looks like you're declaring your controller as inheriting from NSObject, instead of NSWindowController.

编辑:从您的完整代码看起来您​​声明您的控制器继承自NSObject,而不是NSWindowController。

#2


Just as it says, showWindow isn't defined on the PreferenceController class. In C++, this would be an error because it's statically typed and would say "method not defined", but since Objective-C is more flexible, this is only a warning. Without seeing the code, it's hard to tell what your mistake is though.

正如它所说,showWindow没有在PreferenceController类上定义。在C ++中,这将是一个错误,因为它是静态类型的并且会说“方法未定义”,但由于Objective-C更灵活,这只是一个警告。没有看到代码,很难说出你的错误是什么。