Code:
pin color change, the effect of falling can not get out
customAnnotation.h
@ Interface customAnnotation: NSObject
{
CLLocationCoordinate2D coordinate;
NSString * title;
NSString * subtitle;
}
@ Property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@ Property (nonatomic, retain) NSString * title;
@ Property (nonatomic, retain) NSString * subtitle;
- (Id) initCustomeAnnotation: (CLLocationCoordinate2D) coords;
customAnnotation.m
@ Implementation customAnnotation
@ Synthesize coordinate, title, subtitle;
- (Id) initCustomeAnnotation: (CLLocationCoordinate2D) coords {
if (self = [super init]) {
coordinate = coords;
}
return self;
}
- (Void) dealloc {
[Self.title release];
[Self.subtitle release];
[Super dealloc];
}
@ End
viewController.m
@ Implementation ipadMapViewController
- (MKAnnotationView *) mapView: (MKMapView *) theMapView viewForAnnotation: (id) annotation {
MKPinAnnotationView * pinView = (MKPinAnnotationView *) [theMapView dequeueReusableAnnotationViewWithIdentifier: annotation.title];
if (pinView == nil) {
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: annotation.title] autorelease];
pinView.animatesDrop = YES;
pinView.canShowCallout = YES;
pinView.pinColor = MKPinAnnotationColorGreen;
}
else {
pinView.annotation = annotation;
}
NSLog (@ "set green");
return pinView;
}
- (IBAction) buttonPressed: (id) sender {
CLLocationCoordinate2D coords;
coords.latitude = 37.331689;
coords.longitude = 122.030731;
float zoomLevel = 0.018;
MKCoordinateRegion region = MKCoordinateRegionMake (coords, MKCoordinateSpanMake (zoomLevel, zoomLevel));
[PmapView setRegion: [pmapView regionThatFits: region] animated: YES];
customAnnotation * annotation = [[customAnnotation alloc] initCustomeAnnotation: coords];
annotation.title = @ "Apple";
annotation.subtitle = @ "Subtitle";
[PmapView addAnnotation: annotation];
[Annotation release];
}
............
@ End
Reply:
Forgotten by the original sentence mapView.delegate = self
Reply:

Reply:
Details are important
Reply:
I just encountered this problem, see this article solved, newbie questions
No comments:
Post a Comment