我有一个只有一个注释的地图.我创建了一个简单的类,我希望它在用户点击注释时显示.问题是当我点击注释时没有任何反应.
这是我的代码:
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark{
NSLog(@"Reverse Geocoder completed");
mPlacemark=placemark;
[mapView addAnnotation:placemark];
}
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
annView.animatesDrop=TRUE;
//create UIButton for annotation
UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
//NSInteger annotationValue = [self.annotations indexOfObject:annotation];
[detailButton addTarget:self action:@selector(showDetailView:) forControlEvents:UIControlEventTouchUpInside];
annView.rightCalloutAccessoryView=detailButton;
return annView;
}
-(void)showDetailView:(id)sender{
NSLog("inside the stupid method");
MyDetailViewController *detailView=[[MyDetailViewController alloc] initWithNibName:@"MyDetailViewController" bundle:nil];
[[self navigationController] pushViewController:detailView animated:YES];
[detailView release];
}
Run Code Online (Sandbox Code Playgroud)
我的showDetailView功能永远不会被调用.请帮助我.我是iphone的新手,我可能会忘记一件简单的事情.谢谢
还是行不通!!!!
我在我的应用程序中有一个mapView,我正在使用我自己的图像作为MKAnnotationView,这是pin图像.这是我设置它的代码.
-(RMAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(RentPin *)annotation{
static NSString *identifier = @"MyLocation";
if ([annotation isKindOfClass:[RentPin class]]) {
RMAnnotationView *annotationView = (RMAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if(annotationView == nil){
annotationView = [[RMAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
annotationView.enabled = YES;
annotationView.canShowCallout = NO;
annotationView.image = [UIImage imageNamed:@"home44.png"];
annotationView.centerOffset = CGPointMake(-10, -10);
}else{
annotationView.annotation = annotation;
}
return annotationView;
}
return nil;
}
Run Code Online (Sandbox Code Playgroud)
它工作正常,自定义图像也正常显示,但当我捏mapView以放大/缩小地图时,我注意到自定义图像在地图上失去了准确性.请看下面的图片.
https://www.dropbox.com/s/irrgmohppf08fzr/image1.png 此图显示引脚位于此位置,非常准确.
https://www.dropbox.com/s/vvlr4ckk6molqd7/image2.png 缩小mapView后,针脚穿过街道,显示该地址在湖中....
(对不起链接,因为由于声誉不足而无法发布图片.)
有人可以帮我这个吗?我的图像是44x44,我也尝试设置引脚的centerOffset,它无法在所有缩放级别动态解决这个问题.