0

なぜ動かないのか理解できません。

マーカー付きの地図があります。アイコンを変更したいのですが

map.h:

#define METERS_PER_MILE 1609.344

@interface Map : UIViewController<CLLocationManagerDelegate,MKMapViewDelegate>{

IBOutlet MKMapView *map;
CLLocationManager *locationManager;
}


@property(nonatomic,retain) IBOutlet MKMapView *map;
@property(nonatomic,retain)IBOutlet UIWindow *window;
@property (nonatomic, readwrite) CLLocationCoordinate2D location;


- (void)setMarkers:(MKMapView *)mv;
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation;

@end

そしてmap.mでこれ:

@implementation Map

@synthesize map, window, location;


- (void)setMarkers:(MKMapView *)mv 
{
 //no necesary here

}


- (void)viewWillAppear:(BOOL)animated {
// 1
location.latitude = 38.989567;
location.longitude= -1.856283;
// 2
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(location, 0.8*METERS_PER_MILE, 0.8*METERS_PER_MILE);
// 3
MKCoordinateRegion adjustedRegion = [map regionThatFits:viewRegion];
// 4
[map setRegion:adjustedRegion animated:YES];

//[self setMarkers: map];

CLLocationCoordinate2D pointCoord = location;
NSString *theTitle = @"title";
NSString *theSubtitle = @"subtitle";

MapPoint *mp = [[MapPoint alloc] initWithCoordinate:pointCoord title:theTitle subTitle:theSubtitle];
[map addAnnotation:mp];


}

 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {

   NSLog(@"here!!");
static NSString *identifier = @"MyLocation";
if ([annotation isKindOfClass:[MapPoint class]]) {

    MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [map dequeueReusableAnnotationViewWithIdentifier:identifier];
    if (annotationView == nil) {
        annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
    } else {
        annotationView.annotation = annotation;
    }

    annotationView.enabled = YES;
    annotationView.canShowCallout = YES;
    annotationView.image=[UIImage imageNamed:@"Icon.png"];//here we use a nice image instead of the default pins

    return annotationView;
}

return nil;
}

@end

viewForAnnotationは実行されません(NSLogでこれを確認します)

私は何をすべきか?

前もって感謝します

4

1 に答える 1

2

コードに問題はないようです。phix23が言ったように、MKMapViewをデリゲートにリンクするのを見逃したかもしれません:

例01

例02

于 2012-08-21T12:49:27.753 に答える