开发者

Can't call "MapAnnotation" When Trying To Code Pin Locations

开发者 https://www.devze.com 2023-04-11 07:27 出处:网络
I can\'t call the class \"MapAnnotation\" on XCode 4. I\'m working on coding that will allow me to place pins in an MKMapView. I believe I\'ve imported the right delegates. Here\'s what I\'ve got:

I can't call the class "MapAnnotation" on XCode 4. I'm working on coding that will allow me to place pins in an MKMapView. I believe I've imported the right delegates. Here's what I've got:

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

And here's my view controller for the map view:

MapViewController.h

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>

@interface MapViewController : UIViewController <MKMapViewDelegate> {
    IBOutlet MKMapView *mapView;

}

@end

MapViewController.m (just the segment I'm looking at)

#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
    }

I'm wondering if I haven't imported the rights classes or something. I've Googled it and can't seem to find where "MapAnnotation" lies. What do I need to import to get access to "MapAnnotation"? Everything works fine up until that point.

Thanks for the help. I'm just learning this stuff!


What makes you think that there is class called MapAnnotation? Your annotation class is called MillersLocations. You need to create instances of that class and call [mapView addAnnotation:millersLocationInstance]; (or something similar).

0

精彩评论

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

关注公众号