5

当我尝试构建我的项目时,我在 XCode 中遇到构建语义错误。我NSOperation设置了 3 个类来从 Internet 下载信息,对其进行处理,并将其发送到父视图控制器,即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,只有一个在工作。

视图控制器.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
4

1 回答 1

12

尝试在 CurrentGetter 头文件中对类进行前向声明,如下所示:

@class ViewController;
@interface CurrentGetter : NSOperation

这告诉编译器存在一个名为“ViewController”的类。当存在循环依赖时,例如当两个类具有彼此的实例时,使用类的前向声明可以解决由此产生的混乱。

于 2013-03-04T16:44:28.960 回答