未定义的符号:"_ OBJC_CLASS_ $ error

cms*_*cms 24 xcode linker objective-c ios

我一直在查看有关此错误的无数帖子:

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
Run Code Online (Sandbox Code Playgroud)

BoxView是一个子类UIView,并且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];  
}  
Run Code Online (Sandbox Code Playgroud)

BoxView包含此代码:

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

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

BoxView *newView = [[BoxView alloc] initWithFrame:rect];
Run Code Online (Sandbox Code Playgroud)

当我换BoxViewUIView该行时,错误消失了.有谁知道我需要在这里改变什么?我已经浏览过很多关于此的帖子,但是大多数答案都说这与链接有关,但我尝试勾选并解开某些方框而没有成功.我想知道错误是否在我的代码中?任何建议,将不胜感激!

Ben*_*her 45

通常,当代码BoxView未正确编译到目标中时,会发生这种情况.

身份编辑截图

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

"清洁和建造"也不会受到伤害.