当我点击一个图钉时,我试图添加一个视图,但只显示标题和副标题,而不是我添加的视图。
这是我的代码
-(void) inserirMapa {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
NSMutableArray *pins = [[NSMutableArray alloc]init]; //array de Annotations
for(int iCnt = 0; iCnt < [_listaPins count]; iCnt++) {
Pin *pin = (Pin *) [_listaPins objectAtIndex:iCnt];
CLLocationCoordinate2D start;
start.latitude = pin.place.latitude;
start.longitude = pin.place.longitude;
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(start, 800, 800);
[_myMapView setRegion:[_myMapView regionThatFits:region] animated:YES];
// Add an annotation
MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
point.coordinate = start;
point.title = @"Where am I?";
point.subtitle = @"I'm here!!!";
[_myMapView addAnnotation:point];
[pins addObject:point];//adiciona a annotation no array
[point release];
}
self.myAnnotations= [NSArray arrayWithArray:pins]; //diz que o array myAnnotations é igual ao array estacionamentos(que contem as annotations
[pins release];
[self configurarZoomDoMapaComLatitude:appDelegate.latitude eLongitude:appDelegate.longitude]; //configura o Zoom inicial do mapa
[_myMapView addAnnotations:_myAnnotations];
[_viewLoading setHidden:YES];
}
在这里我添加了自定义视图。我在这里放了一个断点并调用了这个函数,但是当我点击一个图钉时,只显示标题和副标题..忽略我添加的视图
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView* annotationView = nil;
//your code
UIView *vw = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
vw.backgroundColor = [UIColor redColor];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 50, 50)];
label.numberOfLines = 4;
label.text = @"hello\nhow are you\nfine";
[vw addSubview:label];
annotationView.leftCalloutAccessoryView = vw;
return annotationView;
}