xcode 找不到“UIView”的接口声明

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26306134/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:50:32  来源:igfitidea点击:

Cannot find interface declaration for 'UIView'

iosobjective-cxcode

提问by Zaxter

I'm trying to add an objective C library for toaststo my xcode project. But I'm getting a number of these errors:

我正在尝试为我的 xcode 项目添加一个客观的 C。但是我收到了一些这样的错误:

"Cannot find interface declaration for 'UIView'"

"Cannot find interface declaration for 'UIView'"

"Expected a type"

"Expected a type"

I have linked with the QuartzCore.framework. And the .m file has been added to compile sources. What am I missing? I'm a newbie to ios. Please help.

我已经链接到 QuartzCore.framework。并且已添加 .m 文件以编译源代码。我错过了什么?我是ios的新手。请帮忙。

回答by rob mayoff

This is a bug in the library. The header file (UIView+Toast.h) uses UIViewbut doesn't import <UIKit/UIKit.h>, so copying its source files into your project can give you this error.

这是库中的错误。头文件 ( UIView+Toast.h) 使用UIView但不使用import <UIKit/UIKit.h>,因此将其源文件复制到您的项目中可能会出现此错误。

(UPDATE: This bug was fixed on October 14, 2014.)

更新此错误已于 2014 年 10 月 14 日修复。

One way to fix this is to add #import <UIKit/UIKit.h>to the top of UIView+Toast.h.

解决此问题的一种方法是添加#import <UIKit/UIKit.h>UIView+Toast.h.

Another way is to add #import <UIKit/UIKit.h>to your target's .pchfile in the “Supporting Files” group, if your project has a .pchfile. It looks like Xcode 6's project templates don't include a .pchfile, so you might not be able to use this fix easily.

如果您的项目有文件,另一种方法是添加#import <UIKit/UIKit.h>.pch“支持文件”组中的目标.pch文件。看起来 Xcode 6 的项目模板不包含.pch文件,因此您可能无法轻松使用此修复程序。

回答by Macondo2Seattle

Be sure to include UIKit, which is where UIViewis defined: #import <UIKit/UIKit.h>

一定要包含 UIKit,它UIView是定义的地方:#import <UIKit/UIKit.h>