不能使用自定义类的类型了 - 这打破了
问题描述:
我有一个奇怪的问题,这是我的Headerfile ViewController.h不能使用自定义类的类型了 - 这打破了
#import <UIKit/UIKit.h>
#import "MapField.h"
@interface ViewController : UIViewController{
IBOutlet UIView *simField;
IBOutlet UISegmentedControl *segmentControl;
IBOutlet UILabel *timeLabel;
double fieldAlpha;
IBOutlet UISlider *alphaSlider;
double tickTime;
int totalNumberOfCars;
}
/*shortened, here are the property ... declarations usually */
-(MapField*)findDepartureField;
-(MapField*)findDestinationField;
类MapField.h看起来像这样:
#import <UIKit/UIKit.h>
#import "ViewController.h"
@interface MapField : UIImageView{
UIViewController *delegate;
int x;
int y;
int numberOfCars;
double wAb;
double wAn;
int dFahrtdauer;
}
@property (nonatomic) int x;
@property (nonatomic) int y;
@property (nonatomic) int numberOfCars;
@property (nonatomic) double wAb;
@property (nonatomic) double wAn;
@property (nonatomic) int dFahrtdauer;
@property (nonatomic, retain) UIViewController *delegate;
-(void)setDisplayMode:(int)mode;
@end
看起来很好,总是能正常工作,但我在ViewController.h得到一个奇怪的错误在这两条线:
-(MapField*)findDepartureField;
-(MapField*)findDestinationField;
错误:电子xpected一个类型(并且MapField标记为红色)。
我不明白。我检查了一千次。它必须工作!其他地方肯定会出现一些奇怪的错误!
答
添加@class MapField
刚刚在您的@interface
上面调用ViewController,告诉编译器,是的,它是一个类。
答
消除#import ViewController.h
从MapField
和添加@class ViewController
(如有必要)将工作。对我来说,问题似乎是.h文件的循环引用,并且参考ViewController.h
似乎没有必要。如果需要,您可以使用@class
转发申报ViewController
类。