开发者

errors when trying to get the value of a variable in another view

please i got errors when i try to read the content of a variable in view2 which was initialized in view1, i explain :

view1 is named RechercherViewCo开发者_C百科ntroller

view2 is named 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;
}

when building the app, i got actually two errors :

error: expected specifier-qualifier-list before 'StationsSurLaCarteViewController'

and

error: accessing unknown 'typeCarburantChoisi' class method

thx for help :)


First of all you have defined an instance property typeCarburantChoisi but in your StationsSurLaCarteViewController.m code you are trying to access kind of a class property (btw, there is no such thing in Objective-C). You will instead need a reference to your RechercherViewController instance and ask it for the property – this will resolve the second compiler error.

Regarding the first error I am not really sure what happened here. Maybe you have an error in your RechercherViewController.h file?
In any case, you should rather not import the interface file into StationsSurLaCarteViewController.h. Instead, use

@class RechercherViewController;

and import the full declaration in your implementation file StationsSurLaCarteViewController.m only.

Also, did you mix up AideStationsSurLaCarteViewController and RechercherViewController in your example?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜