This maybe a simple mistake but i just can’t seem to find out what is wrong with the error Unknown type name 'TransportViewController'. I am trying to pass xCoor and yCoor which is 2 double value to my 2nd view which is the TransportViewController. Here is my codes:
TransportViewController *xCoor;
TransportViewController *yCoor;
@property (retain, nonatomic) TransportViewController *xCoor;
@property (retain, nonatomic) TransportViewController *yCoor;
This 4 line is giving me the error
MapViewController.h file
#import "TransportViewController.h"
@interface MapViewController : UIViewController{
TransportViewController *xCoor;
TransportViewController *yCoor;
}
@property (retain, nonatomic) TransportViewController *xCoor;
@property (retain, nonatomic) TransportViewController *yCoor;
MapViewController.m file
#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 file
#import "MapViewController.h"
@interface TransportViewController : UIViewController<UITextFieldDelegate>
{
double xGPSCoordinate;
double yGPSCoordinate;
}
@property(nonatomic)double xGPSCoordinate;
@property(nonatomic)double yGPSCoordinate;
@end
You have a circular dependency. In short, you have directed the compiler:
MapViewController.hneedsTransportViewController.hTransportViewController.hneedsMapViewController.hIn actuality – neither are necessary in the headers. You can use Forward Declarations in both cases.
MapViewController.h
TransportViewController.h
then your
#imports can go in the*.mfile where needed.you should read up on forward declarations. you can’t use them everywhere, but you can use them very often in headers instead of
#import, and the can really reduce your build times.