当我尝试构建我的项目时,我在 XCode 中遇到构建语义错误。我有 3 个 NSOperation
类设置来从互联网下载信息,处理它,并将它发送到父 View Controller ,一个 ViewController
的实例。这是 worker 类(Class)的代码:
#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
最佳答案
尝试在 CurrentGetter 头文件中对类进行前向声明,如下所示:
@class ViewController;
@interface CurrentGetter : NSOperation
这告诉编译器存在一个名为“ViewController”的类。当存在循环依赖时,例如当两个类具有彼此的实例时,使用类的前向声明可以解决由此产生的混淆。
关于iphone - ViewController 类型名称在一个类中无法识别,但在另一个类中却可以识别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15206437/