我试图在我的地图注释上显示标注时遇到此异常,即使标题已设置.
这是我在MapAnnotation类中使用的init方法:
- (id)initWithTitle:(NSString *)ttl subtitle:(NSString *)sub andCoordinate:(CLLocationCoordinate2D)c2d { titles = ttl; coordinate = c2d; subtitle = sub; return self; }
然后,在另一个类的某个地方,我正在创建注释(两种不同方法中的2):
MapAnnotation *annotation = [[MapAnnotation alloc] initWithTitle:[formatter stringFromDate:sourceDate] subtitle:@"test" andCoordinate:CLLocationCoordinate2DMake(point.latitude,point.longitude)]; [self.mapView addAnnotation:annotation];
这是注释方法:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{ if (annotation == mapView.userLocation) return nil; static NSString *s = @"ann"; MKAnnotationView *pin = [mapView dequeueReusableAnnotationViewWithIdentifier:s]; if (!pin) { pin = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:s]; pin.canShowCallout = YES; pin.image = [UIImage imageNamed:@"pin.png"]; pin.calloutOffset = CGPointMake(0,0); } return pin; }
我想做的另一件事是为两个地图注释使用两个不同的图像.
任何的想法?
谢谢.