MKMapView不调用委托方法

时间:2012-08-10 05:10:55

标签: ipad annotations mkmapview

我正在尝试在地图上删除引脚,但它没有调用委托方法

  
      
  • (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation {
  •   

我的应用程序是通用的,所以当我使用iPhone时,它会正确调用委托方法,但是当我使用iPad时,则不会调用委托方法。 代码如下:

  
      
  • (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation {

         

    static NSString * identifier = @“MachineLocation”;
      if([注释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];
                }


            }

0 个答案:

没有答案