2011-08-15 28 views
2

我相信這真的很愚蠢,但我似乎不明白爲什麼我會得到這個錯誤。在我的項目中,我有一個視圖控制器和另一個做一些數據構造工作的類(無論如何)。當我嘗試在我的類中實例化時,出現編譯錯誤:「未知類型名稱」視圖控制器「」。錯誤實例化其他視圖控制器

這是我班的.h:

#import <Foundation/Foundation.h> 
#import <MapKit/MapKit.h> 
#import "MyLocationController.h" 
#import "GetZip.h" 
#import "SecondTab.h" 

@interface DataEngine : NSObject <MyLocationControllerDelegate, MKMapViewDelegate, GetZipcodeDelegate> { 

MyLocationController *CLController; 
GetZip *getzip; 
SecondTab *secondTab; //ERROR IS HERE 

} 

我的視圖控制器的.h:

#import <UIKit/UIKit.h> 
#import "FirstTab.h" 
#import "DataEngine.h" 

@interface SecondTab : UIViewController <UITableViewDelegate, UITableViewDataSource> { 

IBOutlet UITableView *table1; 
NSString *address; 
NSDate *time; 
NSDictionary *dataDict; 
    DataEngine *fullData; 

} 

(我省略了所有的@synthesis,因爲我不認爲他們沒關係......在任何情況下, ,我做@property(非原子,保留)的一切)。

有什麼想法可以在這裏出錯?

回答

7

你爲什麼不嘗試轉發聲明它。使用@class secondTab而不是#import secondTab?這將有助於避免任何循環包含問題。

+0

+1謝謝,Manish。這似乎正在完成這項工作!任何想法可能會出錯? (什麼是@class和#import之間的差異?:/)。 – TommyG

+1

http://stackoverflow.com/questions/322597/class-vs-import你可能有一個循環依賴關係,兩個類互相依賴。無論如何,湯米總是善於使用前瞻性聲明來避免這些問題。 –

+0

現在我似乎不能允許+ init SecondTab,但是......這是預期的嗎? – TommyG

相關問題