2013-03-04 50 views
5

當我嘗試構建我的項目時,XCode中出現構建語義錯誤。我有3 NSOperation類設置從互聯網下載信息,處理它,並將其發送到父視圖控制器,ViewController的實例。下面是一個工人階級的代碼:ViewController類型名稱在一個類中不被識別,但它在另一個類中?

#import <Foundation/Foundation.h> 
#import "ViewController.h" 

@interface ImageGetter : NSOperation 

@property (nonatomic) int sid; 
@property (nonatomic, retain) ViewController* pvc; 

@end 

下面是一個是工作代碼:

#import <Foundation/Foundation.h> 
#import "ViewController.h" 

@interface CurrentGetter : NSOperation 

@property (nonatomic) int sid; 
@property (nonatomic, retain) ViewController* pvc; 

@end 

錯誤:

ERROR: Unknown type name 'ViewController'; did you mean 'UIViewController'? 

爲什麼我收到這個錯誤?我在兩個文件中導入了ViewController.h,只有一個正在工作。

ViewController.h:

#import <UIKit/UIKit.h> 
#import <AVFoundation/AVFoundation.h> 
#import <MediaPlayer/MediaPlayer.h> 

#import "DataGetter.h" 
#import "CurrentGetter.h" 
#import "AppDelegate.h" 

@interface ViewController : UIViewController <UITabBarDelegate> 
{ 
    NSTimer* tmr; 
} 

@property (nonatomic) float max; 
@property (nonatomic, retain) NSDictionary* plist; 
@property (nonatomic, retain) NSArray* processingobj; 

@property (nonatomic, retain) AVAudioPlayer* intro; 
@property (nonatomic, retain) AVAudioPlayer* woop; 

@property (nonatomic) float dataDone; 
@property (nonatomic) BOOL introDone; 
@property (nonatomic) BOOL currentDone; 

@property (nonatomic) int newSid; 
@property (nonatomic) int newPart; 

@property (nonatomic, retain) NSMutableArray* views; 

@property (nonatomic) int audioTab; 
@property (nonatomic) int currentSid; 
@property (nonatomic) BOOL isPlaying; 

@property (nonatomic, retain) UIScrollView* partTab; 
@property (nonatomic, retain) NSMutableArray* nowPlayingObj; 
@property (nonatomic, retain) UINavigationBar* audioNav; 

@property (nonatomic, retain) MPMoviePlayerController* player; 
@property (nonatomic, retain) UILabel* elapsed; 
@property (nonatomic, retain) UILabel* remaining; 
@property (nonatomic, retain) UISlider* slider; 
@property (nonatomic) BOOL sliderEditing; 
@property (nonatomic, retain) UIButton* playBtn; 

@property (nonatomic, retain) UITabBar* tabBar; 

//Images 

@property (nonatomic, retain) UIImage* announcement; 
@property (nonatomic, retain) NSMutableArray* seriesBanners; 
@property (nonatomic, retain) UIProgressView* prog; 

- (void)plistDone; 

@end 
+0

.m文件是否添加到您的目標? – 2013-03-04 16:39:57

+0

顯示ViewController.h的內容 – 2013-03-04 16:48:33

+0

您是否嘗試過Clean? – 2013-03-04 16:52:27

回答

12

嘗試做之類的前向聲明在CurrentGetter頭文件中,就像這樣:

@class ViewController; 
@interface CurrentGetter : NSOperation 

這告訴編譯器存在一個所謂的「類視圖控制器「。當存在循環依賴關係時(例如兩個類彼此具有實例時),使用類的前向聲明可解決導致的混淆問題。

+0

那麼構建成功與該行。你能解釋爲什麼這個工作? – David 2013-03-04 17:10:50

+0

對,對不起。我對這個網站有點新鮮,所以我忘記了包括解釋在內被認爲是一種很好的形式。我的簡短解釋是否有意義? – ewrobinson 2013-03-04 17:12:45

+0

那麼爲什麼當CurrentGetter沒有,即使它們有完全相同的代碼,ImageGetter類也能正確構建? – David 2013-03-04 17:12:46

相關問題