我正在尝试在地图上放置图钉,但它没有调用委托方法
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation{
我的应用程序是通用的,所以当我使用 iPhone 时,它会正确调用委托方法,但是当我使用 iPad 时,不会调用委托方法。代码如下:
(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation{
静态 NSString *identifier = @"MachineLocation";
if ([annotation isKindOfClass:[MachineLocation class]]) {MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier]; if (annotationView == nil) { annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier]; } else { annotationView.annotation = annotation; } annotationView.enabled = YES; annotationView.canShowCallout = YES; // if (isWeatherOn) { if (imageFlag == 0) { annotationView.image=[UIImage imageNamed:@"Clouds.png"]; } if (imageFlag == 1) { annotationView.image=[UIImage imageNamed:@"Sun + Clouds.png"]; } if (imageFlag == 2) { annotationView.image=[UIImage imageNamed:@"Sun.png"]; } imageFlag++; } else { annotationView.image=[UIImage imageNamed:@"arrest.png"]; NSLog(@"annotation"); } annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; return annotationView;
}
返回零;}
viewWillApear 下的代码是这个
NSString *tempString;
for(NSMutableArray *array in appDelegate.globalVehicleInfoArray) {
for (VehicleInfo *vehicleInfo in array) {
for (WeatherCondition *weather in appDelegate.globalWeatherConditionArray) {
if ([weather.weatherID isEqualToString:[vehicleInfo vehicleID]]) {
tempString = [weather weatherTempC];
// NSLog(@"weather id matched");
}
}
NSString *name = [vehicleInfo vehicleName];
NSString *machineDescription = [NSString stringWithFormat:@"%@ %@ C", [vehicleInfo vehicleLastUpdate], tempString];
MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
CLLocationCoordinate2D coordinate;
coordinate.latitude = [[vehicleInfo vehicleLastPositionY] doubleValue];
coordinate.longitude = [[vehicleInfo vehicleLastPositionX] doubleValue];
NSLog(@"%f , %f", coordinate.latitude, coordinate.longitude);
MachineLocation *location = [[MachineLocation alloc] initWithId:[vehicleInfo vehicleID] :name description:machineDescription coordinate:coordinate];
// annotation.coordinate = coordinate;
[self.mapView addAnnotation:location];
}
}