2013-03-14 59 views
0

enter image description here如何正确导入Objective-C的

头文件,我导入PaiLifeCardLeftViewController.h但Xcode的告诉我,这是一个未知类型。

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

编辑:PaiLifeCardLeftViewController.h: enter image description here

+1

你能告诉我们'PaiLifeCardLeftViewController.h'吗? – Sebastian 2013-03-14 01:33:40

+0

@Sebastian它是。 PaiLifeCardLeftViewController.h – jxdwinter 2013-03-14 01:40:10

+0

就像您在屏幕截图中建议的Xcode一样,您只是使用了不正确的大小写。 Pai ** L ** ifeCardLeftViewController! – Till 2013-03-14 02:16:52

回答

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声明实例变量。它会为你合成。

+0

非常感谢!你太棒了 ! – jxdwinter 2013-03-14 02:30:37

1

您可以通过@interface语句前加上

@class PaiLifeCardCenterViewController

作出正向类声明的类。

+0

不,它不起作用,但谢谢。 – jxdwinter 2013-03-14 01:40:47