请尝试在view1中初始化的view2中读取变量的内容时出现错误,我解释说:
view1被命名为RechercherViewController
view2被命名为StationsSurLaCarteViewController
RechercherViewController.h:
@property (nonatomic,copy) NSString *typeCarburantChoisi;
RechercherViewController.m:
@synthesize typeCarburantChoisi;
StationsSurLaCarteViewController.h
#import "RechercherViewController.h"
@interface StationsSurLaCarteViewController : UIViewController {
IBOutlet AideStationsSurLaCarteViewController *aideStationsSurLaCarteViewController;
IBOutlet UITextField *textField;
}
@end
StationsSurLaCarteViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
textField.text=RechercherViewController.typeCarburantChoisi;
}
在构建应用程序时,我实际上遇到了两个错误:
error: expected specifier-qualifier-list before 'StationsSurLaCarteViewController'
和
error: accessing unknown 'typeCarburantChoisi' class method
寻求帮助:)
最佳答案
首先,您已经定义了一个实例属性typeCarburantChoisi
,但是在您的StationsSurLaCarteViewController.m
代码中,您试图访问一种类属性(顺便说一句,Objective-C中没有这样的东西)。您将需要对您的RechercherViewController
实例的引用,并要求其提供属性-这将解决第二个编译器错误。
关于第一个错误,我不确定在这里发生了什么。也许您的RechercherViewController.h
文件有错误?
无论如何,您不应该将接口文件导入到StationsSurLaCarteViewController.h
中。相反,使用
@class RechercherViewController;
并将完整的声明仅导入到实现文件
StationsSurLaCarteViewController.m
中。另外,您在示例中是否混用了
AideStationsSurLaCarteViewController
和RechercherViewController
?