我已经阅读了无数关于这个错误的帖子:
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
BoxView
是 UIView
的子类,并且已经包含了 UIKit
框架。在 ViewController 中已经导入了 BoxView.h
。
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
,错误就消失了。有人知道我需要在这里改变什么吗?我查看了许多关于此问题的帖子,但大多数答案都说与链接相关,但我尝试了勾选和取消勾选某些框,但没有成功。我想知道错误是否在我的代码中?任何建议都将不胜感激!