头文件,我导入PaiLifeCardLeftViewController.h但Xcode的告诉我,这是一个未知类型。
我该如何解决这个问题,谢谢。
编辑:PaiLifeCardLeftViewController.h:
头文件,我导入PaiLifeCardLeftViewController.h但Xcode的告诉我,这是一个未知类型。
我该如何解决这个问题,谢谢。
编辑:PaiLifeCardLeftViewController.h:
此问题是由PaiLifeCardLeftViewController
和PaiLifeCardCenterViewController
之间的循环依赖造成的。每个相应的.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
声明实例变量。它会为你合成。
非常感谢!你太棒了 ! – jxdwinter 2013-03-14 02:30:37
您可以通过@interface
语句前加上
@class PaiLifeCardCenterViewController
作出正向类声明的类。
不,它不起作用,但谢谢。 – jxdwinter 2013-03-14 01:40:47
你能告诉我们'PaiLifeCardLeftViewController.h'吗? – Sebastian 2013-03-14 01:33:40
@Sebastian它是。 PaiLifeCardLeftViewController.h – jxdwinter 2013-03-14 01:40:10
就像您在屏幕截图中建议的Xcode一样,您只是使用了不正确的大小写。 Pai ** L ** ifeCardLeftViewController! – Till 2013-03-14 02:16:52