gpt4 book ai didi

objective-c - undefined symbol : "_OBJC_CLASS_$ error

转载 作者:IT王子 更新时间:2023-10-29 08:02:49 27 4
gpt4 key购买 nike

我一直在浏览关于这个错误的无数帖子:

Undefined symbols:
"_OBJC_CLASS_$_BoxView", referenced from:
objc-class-ref-to-BoxView in ViewMovingViewController.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

BoxViewUIView 的子类,包含了UIKit 框架。 BoxView.h 已导入到 ViewController 中。

ViewController 包含以下代码:

-(void) addBoxViewAtLocation:(CGPoint)point {
CGRect rect;
rect.origin.x = point.x;
rect.origin.y = point.y;
rect.size.width = 80;
rect.size.width = 40;
BoxView *newView = [[BoxView alloc] initWithFrame:rect];
newView.backgroundColor = [UIColor yellowColor];
[mainView addSubview:newView];
}

BoxView 包含这段代码:

- (id)initWithFrame:(CGRect)frame {     
self = [super initWithFrame:frame];
if (self) {
// no further initialization
}
return self;
}

这是导致错误的行,来自上面的代码:

BoxView *newView = [[BoxView alloc] initWithFrame:rect];

当我在该行中将 BoxView 更改为 UIView 时,错误消失了。有谁知道我需要在这里改变什么?我浏览了很多关于此的帖子,但大多数答案都说它与链接相关,但我尝试勾选和取消勾选某些框但没有成功。我想知道错误是否在我的代码中?如有任何建议,我们将不胜感激!

最佳答案

通常,当 BoxView 的代码没有正确编译到您的目标中时,就会发生这种情况。

identity editor screenshot

您需要确保您正在构建的目标已针对您的 BoxView.m 实现文件选中了相应的框。你的问题表明你已经尝试过这个,但为了清楚起见,这里有一个屏幕截图(来自 Xcode 4)。

“清理并构建”也无妨。

关于objective-c - undefined symbol : "_OBJC_CLASS_$ error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6960543/

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