2012-01-30 3 views
1

В моем методе viewDidLoad: я установил MapView таким образом, чтобы, если пользователь выбрал все местоположения, тогда он должен отображать все виды местоположений/пинов, и если только один, тогда только один вывод с булавкой должен быть показано на рисунке.MapView аннотации/контакты в iPhone

- (void)viewDidLoad{ 

[mapView setMapType:MKMapTypeStandard]; 
[mapView setZoomEnabled:YES]; 
[mapView setScrollEnabled:YES]; 

if ([vehicleLabel.text isEqualToString:@"All Vehicles"]) { 

    MKCoordinateRegion region = {{0.0, 0.0},{0.0, 0.0}}; 
    region.center.latitude = 41.01860; 
    region.center.longitude = 28.96470; 
    region.span.longitudeDelta = 0.01f; 
    region.span.latitudeDelta = 0.01f; 
    [mapView setRegion:region animated:YES]; 

    [mapView setDelegate:self]; 

    Annotations *ann = [[Annotations alloc] init]; 
    ann.title = @"Vehicle A"; 
    ann.subtitle = @"VG 1"; 
    ann.coordinate = region.center; 

    [mapView addAnnotation:ann]; 

    NSMutableArray* annotations=[[NSMutableArray alloc] init]; 

    CLLocationCoordinate2D theCoordinate1; 
    theCoordinate1.latitude = 41.01760; 
    theCoordinate1.longitude = 30.96470; 

    CLLocationCoordinate2D theCoordinate2; 
    theCoordinate2.latitude = 41.01860; 
    theCoordinate2.longitude = 31.96470; 

    CLLocationCoordinate2D theCoordinate3; 
    theCoordinate3.latitude = 41.01360; 
    theCoordinate3.longitude = 25.96470; 

    CLLocationCoordinate2D theCoordinate4; 
    theCoordinate4.latitude = 41.01560; 
    theCoordinate4.longitude = 27.96470; 

    Annotations* myAnnotation1=[[Annotations alloc] init]; 

    myAnnotation1.coordinate=theCoordinate1; 
    [email protected]"Vehicle B"; 
    [email protected]"Group 1"; 

    Annotations* myAnnotation2=[[Annotations alloc] init]; 

    myAnnotation2.coordinate=theCoordinate2; 
    [email protected]"Vehicle C"; 
    [email protected]"Group 1"; 

    Annotations* myAnnotation3=[[Annotations alloc] init]; 

    myAnnotation3.coordinate=theCoordinate3; 
    [email protected]"Vehicle D"; 
    [email protected]"Group 1"; 

    Annotations* myAnnotation4=[[Annotations alloc] init]; 

    myAnnotation4.coordinate=theCoordinate4; 
    [email protected]"Vehicle E"; 
    [email protected]" Group 1"; 

    [mapView addAnnotation:myAnnotation1]; 
    [mapView addAnnotation:myAnnotation2]; 
    [mapView addAnnotation:myAnnotation3]; 
    [mapView addAnnotation:myAnnotation4]; 

    [annotations addObject:myAnnotation1]; 
    [annotations addObject:myAnnotation2]; 
    [annotations addObject:myAnnotation3]; 
    [annotations addObject:myAnnotation4]; 

    NSLog(@"Annotations: %d",[annotations count]); 
} 
else { 

MKCoordinateRegion region = {{0.0, 0.0},{0.0, 0.0}}; 
region.center.latitude = 41.01860; 
region.center.longitude = 28.96470; 
region.span.longitudeDelta = 0.01f; 
region.span.latitudeDelta = 0.01f; 
[mapView setRegion:region animated:YES]; 

[mapView setDelegate:self]; 

Annotations *ann = [[Annotations alloc] init]; 
ann.title = @"Vehicle A"; 
ann.subtitle = @"VG 1"; 
ann.coordinate = region.center; 

[mapView addAnnotation:ann]; 
}} 

- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation{ 

MKPinAnnotationView *pinView = nil; 
if(annotation != mapView.userLocation) 
{ 
    static NSString *defaultPinID = @"aPin"; 
    pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID]; 
    if (pinView == nil) 
     pinView = [[[MKPinAnnotationView alloc] 
        initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease]; 
} else { 
} 
pinView.pinColor = MKPinAnnotationColorRed; 
pinView.canShowCallout = YES; 
pinView.animatesDrop = YES; 
return pinView;} 

И в моем PickerView didSelectRow method: я реализовал:

-(void)pickerView:(UIPickerView *)pickerViewG didSelectRow:(NSInteger)row inComponent:(NSInteger)component{ 

if (component == kGroupComponent) { 
    NSString *selectedState = [self.vehicleGroup objectAtIndex:row]; 
    NSArray *array = [groupVehicles objectForKey:selectedState]; 
    self.vehiclesList = array; 
    [vehiclePicker selectRow:0 inComponent:kListComponent animated:YES]; 
    [vehiclePicker reloadComponent:kListComponent]; 
} 

NSInteger groupRow = [vehiclePicker selectedRowInComponent:kGroupComponent]; 
NSInteger vehicleRow = [vehiclePicker selectedRowInComponent:kListComponent]; 

NSString *group = [self.groupOfVehicles objectAtIndex:groupRow]; 
NSString *vehicle = [self.listVehicles objectAtIndex:vehicleRow]; 

groupLabel.text = [[NSString alloc] initWithFormat: @"%@", group]; 

vehicleLabel.text = [[NSString alloc] initWithFormat: @"%@", vehicle]; 

valueForOtherView = vehicleLabel.text;} 

Вот что я хочу знать, это то, что если пользователь выбирает один автомобиль с точки зрения сборщика, то все другие виды контактных/места должны быть скрытым/удаленным из представления, и должен отображаться только выбранный вид местоположения/вывода.

Как это сделать в этом режиме выбора didSelectRow method:?

ответ

0

Что я делаю в случае подобного вашему, является:

1) сначала удалить все аннотаций

for (id <MKAnnotation> anAnnotation in [NSArray arrayWithArray:mapView_.annotations]) { 
    [mapView_ removeAnnotation:anAnnotation]; 
} 

2), а затем краску выбирают те:

[mapView_ addAnnotation:myAnnotation]; 
Смежные вопросы