为什么我的 Objective C 实现文件无法识别我的导入语句
这是我的头文件
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <PolygonShape.h>
@interface Controller : NSObject {
IBOutlet UIButton *decreaseButton;
IBOutlet UIButton *increaseButton;
IBOutlet UILabel *numberOfSidesLabel;
//IBOutlet PolygonShape *shape;
}
- (IBAction)decrease;
- (IBAction)increase;
@end
这是我的实现文件
#import "Controller.h"
@implementation Controller
- (IBAction)decrease {
//shape.numberOfSides -= 1;
}
- (IBAction)increase {
//shape.numberOfSides += 1;
}
@end
为什么我的 #import "Controller.h"
行出现以下错误?
error: PolygonShape.h: No such file or directory
PolygonShape.h 和 .m 文件与 Controller 类位于同一项目和同一目录中。
Here is my header file
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <PolygonShape.h>
@interface Controller : NSObject {
IBOutlet UIButton *decreaseButton;
IBOutlet UIButton *increaseButton;
IBOutlet UILabel *numberOfSidesLabel;
//IBOutlet PolygonShape *shape;
}
- (IBAction)decrease;
- (IBAction)increase;
@end
Here is my implementation file
#import "Controller.h"
@implementation Controller
- (IBAction)decrease {
//shape.numberOfSides -= 1;
}
- (IBAction)increase {
//shape.numberOfSides += 1;
}
@end
Why am I getting the following error on my #import "Controller.h"
line?
error: PolygonShape.h: No such file or directory
The PolygonShape.h and .m files are in the same project and in the same directory as the Controller class.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尖括号 (
<>
) 表示该文件位于标准包含路径中,例如 /usr/include 或 /System/Library/Frameworks。 要导入相对于当前目录的文件,您需要像在#import "Controller.h"
中那样使用双引号。The angle braces (
<>
) mean that the file is in a standard include path, such as /usr/include or /System/Library/Frameworks. To import a file relative to the current directory, you need to use double-quotes like you do in#import "Controller.h"
.系统头文件使用<>。 你的头文件应该使用“”。
所以应该是:
您可能想在头文件中使用 @class PolygonShape 并在实现中进行导入。
System header files use <>. Your header files should use "".
So it should be:
And you might want to use @class PolygonShape in your header file and do the import in your implementation.
如果你在B中导入A类,然后在A中导入B类,你会得到这个错误
If you import class A in B and then import class B in A you will get this error