当试图编码引脚位置时,无法调用“MapAnnotation”
问题描述:
我无法在XCode 4上调用类“MapAnnotation”。我正在编写允许将引脚放置在MKMapView中的编码。我相信我已经输入了正确的代表。下面是我有:当试图编码引脚位置时,无法调用“MapAnnotation”
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”?一切工作正常,直到那一点。
感谢您的帮助。我只是在学习这些东西!
答
是什么让你觉得有叫MapAnnotation
的课?你的注解类被称为MillersLocations
。您需要创建该类的实例并调用[mapView addAnnotation:millersLocationInstance];
(或类似的东西)。
哦,呃...我的坏。感谢你的回答!我的大脑仍然在超级争夺。我很欣赏快速回答。 – MillerMedia