/ /不明なタイプ名「TransportViewController」-iphone、objective-c、ios、xcode4.3

不明なタイプ名「TransportViewController」-iphone、objective-c、ios、xcode4.3

これはたぶん単純な間違いですが、私はただ「エラーの何が悪いのかを見つけられない Unknown type name "TransportViewController"。 2であるxCoorとyCoorを渡そうとしています。 double TransportViewControllerである私の2番目のビューの値。私のコードは次のとおりです。

TransportViewController *xCoor;
TransportViewController *yCoor;
@property (retain, nonatomic) TransportViewController *xCoor;
@property (retain, nonatomic) TransportViewController *yCoor;

この4行は私にエラーを与えています

MapViewController.hファイル

#import "TransportViewController.h"
@interface MapViewController : UIViewController{
TransportViewController *xCoor;
TransportViewController *yCoor;
}
@property (retain, nonatomic) TransportViewController *xCoor;
@property (retain, nonatomic) TransportViewController *yCoor;

MapViewController.mファイル

#import "TransportViewController.h"
@implementation MapViewController
@synthesize xCoor;
@synthesize yCoor;
.
.
.
- (IBAction) publicTransportAction:(id)sender{
TransportViewController *view = [[TransportViewController alloc] initWithNibName:nil bundle:nil];
self.xCoor = view;
self.yCoor = view;
xCoor.xGPSCoordinate = self.mapView.gps.currentPoint.x;
yCoor.xGPSCoordinate = self.mapView.gps.currentPoint.y;
[self presentModalViewController:view animated:NO];
}

TransportViewController.hファイル

#import "MapViewController.h"
@interface TransportViewController : UIViewController<UITextFieldDelegate>
{
double xGPSCoordinate;
double yGPSCoordinate;
}
@property(nonatomic)double xGPSCoordinate;
@property(nonatomic)double yGPSCoordinate;
@end

回答:

回答№1は1

循環依存関係があります。要するに、あなたはコンパイラを指示しました:

  • MapViewController.h ニーズ TransportViewController.h
  • そして TransportViewController.h ニーズ MapViewController.h

実際に - どちらも ヘッダーに必要です。使用できます 前方宣言 両方の場合において。

MapViewController.h

@class TransportViewController; // << forward declaration instead of inclusion

@interface MapViewController : UIViewController {
TransportViewController *xCoor;
TransportViewController *yCoor;
}
@property (retain, nonatomic) TransportViewController *xCoor;
@property (retain, nonatomic) TransportViewController *yCoor;
@end

TransportViewController.h

@class MapViewController; // << not even needed, as MapViewController
//    does not exist in this header

@interface TransportViewController : UIViewController<UITextFieldDelegate>
{
double xGPSCoordinate;
double yGPSCoordinate;
}
@property(nonatomic)double xGPSCoordinate;
@property(nonatomic)double yGPSCoordinate;
@end

あなたの #importに行くことができます *.m 必要なファイル。

前方宣言を読んでください。どこでも使用することはできませんが、代わりにヘッダーで頻繁に使用することができます #import、そしてビルド時間を本当に短縮できます。