0

在此处输入图像描述

我导入了 PaiLifeCardLeftViewController.h 但 Xcode 告诉我它是未知类型。

我该如何解决这个问题,谢谢。

编辑: PaiLifeCardLeftViewController.h: 在此处输入图像描述

4

2 回答 2

3

此问题是由 和 之间的循环依赖引起PaiLifeCardLeftViewControllerPaiLifeCardCenterViewController。每个对应的 .h 文件都在尝试导入另一个。你不能这样做。

正确的解决方案是更新两个 .h 文件。在两者中,删除另一个 .h 的导入并将其替换为@class前向声明。

PaiLifeCardLeftViewController.h:

#import <UIKit/UIKit.h>
#import "PaiLifeCardRefreshDelegate.h"

@class PaiLifeCardCenterViewController;

@interface PaiLifeCardLeftViewController : UITableViewController

@property (strong, non atomic) id<PaiLifeCardRefreshDelegate> delegate

@end

对 进行类似的更改PaiLifeCardCenterViewController.h

然后您必须将导入添加到 .m 文件。

您应该在 .h 文件中包含尽可能少的导入。如果可能,最好使用 forward ( @class) 声明。它避免了循环依赖,并且使编译速度更快,并且在更改 .h 文件时减少了重新编译。

边注。无需为delegate. 将为您合成。

于 2013-03-14T02:21:52.863 回答
1

您可以通过添加对类进行前向类声明

@class PaiLifeCardCenterViewController

@interface声明之前。

于 2013-03-14T01:35:20.710 回答