【发布时间】:2012-03-31 12:34:46
【问题描述】:
我正在尝试将此类别添加到 CPView,但 XCodeCapp 出现错误,当我尝试使用此方法时收到 unrecognized selector sent to instance 错误。
@import <AppKit/CPView.j>
@implementation CPView (Custom)
- (void) addSomething
{
var bounds = [self bounds];
var context = [[CPGraphicsContext currentContext] graphicsPort];
CGContextSetFillColor(context, [CPColor blueColor]);
CGContextFillRect(context, CGRectMake(100,100,100,100));
}
@end
据我所知语法是正确的,我使用的文件名是 CPView_Custom.j
编辑
我还使用 IB 将 CPView ivar 连接到 XIB/NIB 文件中的自定义视图。不确定这是否会有所不同。
【问题讨论】:
-
@import "CPView_Custom.j"在 AppController.j 的顶部 -
对我来说看起来不错。尝试将代码移动到您正在使用它的文件中。如果它有效,那么问题将与导入相关。
-
@AlexanderLjungberg 我也在使用 IB,可能是错误的根源(刚刚编辑了我的问题)。
-
我确实尝试将代码放入 AppController.j 中,而 XCodeCapp 在处理该文件时出错。所以我觉得这里可能存在与 IB 相关的问题。
-
我已经看到 XcodeCapp 在意想不到的时候出现错误。我通过 Objective-J 编译器运行了你的代码,它编译得很好。您可能想尝试看看它是否适用于非 XIB 测试应用程序。