说 viewController 不是 exist.iOS Xcode 的错误

Error saying the viewController does not exist.iOS Xcode

在我的应用程序中, 它显示了一些错误,例如:

 "unknown type name 'purchasedViewController'; DId you mean 'UIPageViewController'?

但实际上有一个名为purchasedViewController的VC,我已经在当前VC中导入了它。

但是当我在当前 VC 中创建一个 purchasedViewController 的对象时,例如:

@property(strong, nonatomic) purchasedViewController *purchasedController;

我收到一条错误消息:

"unknown type name 'purchasedViewController'; DId you mean 'UIPageViewController'?

为什么会这样?有什么想法吗?

**************编辑************** 这是我的“.h”文件

#import <UIKit/UIKit.h>
#import <StoreKit/StoreKit.h>
#import "PurchasedViewController.h"

@interface MainScreenViewController : UIViewController
- (IBAction)purchaseItemAction:(id)sender;
@property (strong, nonatomic) IBOutlet UILabel *Label;

@property(strong,nonatomic) PurchasedViewController *purchaseController;

-(void)Purchased;

@end

尝试像

这样的前向声明
  @class purchasedViewController;
  @interface MainScreenViewController : UIViewController


  @end  

我认为它适合你

如果 header 以某种方式相互导入,您可能会遇到问题。为避免这种情况,请将 header 中的导入更改为如下所示:

//MainScreenViewController.h

#import <UIKit/UIKit.h>
#import <StoreKit/StoreKit.h>
@class PurchasedViewController;

@interface MainScreenViewController : UIViewController
...

这将告诉 header class 存在但实际上并未导入它。

然后,在 MainScreenViewController 的实现 (.m) 文件中,您实际上可以调用导入:

//MainScreenViewController.m

#import "PurchasedViewController.h"
...