頭文件,我導入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