我无法在XCode 4上调用类“MapAnnotation”。我正在进行编码,这将允许我将引脚放在MKMapView中。我相信我已经导入了合适的代表。这就是我所拥有的:
MillersLocations.h
#import <Foundation/Foundation.h>
#import <MapKit/MKAnnotation.h>
#import <MapKit/MapKit.h>
@interface MillersLocations : NSObject <MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
}
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@end
MillersLocations.m
#import "MillersLocations.h"
@implementation MillersLocations
@synthesize coordinate, title, subtitle;
-(void)dealloc{
[title dealloc];
[subtitle dealloc];
[super dealloc];
}
@end
这是地图视图的视图控制器:
MapViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface MapViewController : UIViewController <MKMapViewDelegate> {
IBOutlet MKMapView *mapView;
}
@end
MapViewController.m(只是我正在看的片段)
#import "MapViewController.h"
#import "MillersLocations.h"
@implementation MapViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
//skipping forward
- (void)viewDidLoad
{
[super viewDidLoad];
MKCoordinateRegion store1;
store1.center.latitude = 36.8605679;
store1.center.longitude = -76.2866713;
store1.span.latitudeDelta = 0.1;
store1.span.longitudeDelta = 0.1;
[mapView setRegion:store1 animated:YES];
//this is where I'm trying to put this code in:
MapAnnotation* annotation = [[MapAnnotation alloc] initWithCoordinate:newCoord];
//BUT "MapAnnotation" isn't an option
}
我想知道我是否没有导入权限类或其他内容。我用谷歌搜索它,似乎无法找到“MapAnnotation”所在的位置。我需要导入什么才能访问“MapAnnotation”?在此之前一切正常。
感谢您的帮助。我只是在学习这些东西!
答案 0 :(得分:0)
是什么让你觉得有一个名为MapAnnotation
的课程?您的注记类称为MillersLocations
。您需要创建该类的实例并调用[mapView addAnnotation:millersLocationInstance];
(或类似的东西)。