我创建了一个新项目并添加了一个名为 MyViewController
的新类。当 MyViewController
是 NSObject
的子类时,我的代码可以正常编译,但是当我将其更改为继承自 UIViewController
时,我收到以下两条错误消息:
Class "MyViewController" defined without specifying a base class
和
Cannot find interface declaration for "UIViewController", superclass of "MyViewController".
我的头文件有什么问题?
MyViewController.h
#import <Foundation/Foundation.h>
@interface LBAHypnosisViewController : UIViewController
@end
最佳答案
基金会不包括UIViewController
,它是 UIKit 的一部分。将其添加到您的头文件中。
#import <UIKit/UIKit.h>
您可能会注意到许多项目在其前缀 header 中同时包含 Foundation 和 UIKit。这会自动将它们包含在每个文件中。旧版本的 Xcode 会在创建新项目时为您执行此操作。
关于ios - 未指定基类而定义的类。找不到 UIViewController 的接口(interface)声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25432951/