我有一個表視圖,必須推入地圖。我試圖從註解中獲得標題以顯示在地圖視圖中,並且我需要比較來自字幕值的值以完全基於註解值顯示在地圖中,但是我在地圖中獲取的是標題和字幕值。 我不想顯示字幕,但我希望它比較值 這裏是我的代碼:如何在地圖視圖中僅顯示引腳(註釋)標題?
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
(id <MKAnnotation>)annotation {
MKAnnotationView *pinView = nil;
if(annotation != mapview.userLocation)
{
NSLog(@"%i",k);
static NSString *defaultPinID = @"defaultPinID";
pinView = (MKAnnotationView *)[mapview dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if (pinView == nil) pinView = [[[MKAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
NSString *[email protected]"0";
NSString *str = [annotation subtitle];
if ([str isEqualToString:st]) {
//pinView.pinColor = MKPinAnnotationColorGreen;
pinView.image=[UIImage imageNamed:@"greyDot.png"];
//return pinView;
}
NSString *[email protected]"10";
if ([str isEqualToString:st1]) {
//pinView.pinColor = MKPinAnnotationColorGreen;
pinView.image=[UIImage imageNamed:@"blackDot.png"];
//return pinView;
}
NSString *[email protected]"20";
if ([str isEqualToString:st2]) {
//pinView.pinColor = MKPinAnnotationColorPurple;
pinView.image=[UIImage imageNamed:@"greendot.png"];
//return pinView;
}
NSString *[email protected]"30";
if ([str isEqualToString:st3]) {
//pinView.pinColor = MKPinAnnotationColorRed;
pinView.image=[UIImage imageNamed:@"blueDot.png"];
//return pinView;
}
pinView.canShowCallout = YES;
infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
//Display *t=annotation;
infoButton.tag=k;
[infoButton addTarget:self action:@selector(pinLabelClicked:) forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = infoButton;
}
else {
[mapview.userLocation setTitle:@"I am here"];
}
return pinView;
//k++;
}
這是我的代碼生成的註釋
- (void)generateAnnotations
{
[mapview setMapType:MKMapTypeStandard];
[mapview setZoomEnabled:YES];
[mapview setScrollEnabled:YES];
[mapview setDelegate:self];
for(int i=0;i<[addressArray count];i++){
AddressInfo *address = [addressArray objectAtIndex:i];
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = [address.latitude floatValue];
region.center.longitude = [address.longitude floatValue];
region.span.latitudeDelta=10.01f;
region.span.longitudeDelta=10.01f;
[mapview setRegion:region animated:YES];
//[mapview setRegion:region animated:TRUE];
//[mapview regionThatFits:region];
DisplayMap *ann = [[DisplayMap alloc] init];
//ann.tt=i;
k=i;
ann.title = address.name;
ann.subtitle = [NSString stringWithFormat:@"%@",address.category];
ann.sa = address.streetaddress;
ann.sb = address.suburb;
ann.ph = address.phoneNo;
ann.index = i;
//ann.image = [NSString stringWi[email protected]"image_%d.png",i];
ann.coordinate=region.center;
[mapview addAnnotation:ann];
[ann release];
}
}
什麼,我在這裏做什麼是我比較基於這個值的類別值我需要在相對顏色的地圖視圖中顯示引腳.. 任何人有想法如何做到這一點?
非常感謝安娜,但使用這種方法我想就能得到的只有一個藍點類別針在圖形頁面,但名單視圖顯示其中三個.... – khadar 2012-08-14 08:14:22
不,對每個註釋單獨調用viewForAnnotation。只要該方法中的邏輯基於傳入的特定註釋,就應該沒問題。如果還存在問題,您可以提出其他問題並添加新的代碼。 – Anna 2012-08-14 13:15:39