1

我有一个表格视图,每行都有名称,每个标题都有不同的图像。我需要将这些标题传递给 mapview,因为注释包含标题名称作为注释的标题。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{

UITableViewCell *cell = nil;
static NSString *AutoCompleteRowIdentifier = @"AutoCompleteRowIdentifier";
cell = [tableView dequeueReusableCellWithIdentifier:AutoCompleteRowIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] 
            initWithStyle:UITableViewCellStyleDefault reuseIdentifier:AutoCompleteRowIdentifier];
}

AddressInfo *addressInfo = [addressList objectAtIndex:indexPath.row];



NSString *str=[NSString stringWithFormat:@"%@",addressInfo.category];
NSString *str2=@"0";
if ([str isEqualToString:str2] ) {
    UIImage *image1=[UIImage imageNamed:@"greyDot.png"];
    cell.imageView.image=image1;
}
NSString *str3=@"10";
if ([str isEqualToString:str3] ) {
    UIImage *image2=[UIImage imageNamed:@"blackDot.png"];
    cell.imageView.image=image2;
}   
NSString *str4=@"20";
if ([str isEqualToString:str4] ) {
    UIImage *image3=[UIImage imageNamed:@"greendot.png"];
    cell.imageView.image=image3;
}   

NSString *str5=@"30";
if ([str isEqualToString:str5] ) {
    UIImage *image4=[UIImage imageNamed:@"blueDot.png"];
    cell.imageView.image=image4;
}

NSString *str6=@"1";
if ([str isEqualToString:str6] ) {
    UIImage *image5=[UIImage imageNamed:@"0Dot.png"];
    cell.imageView.image=image5;
}

cell.textLabel.text = addressInfo.name;
return cell;


}

但是在我的地图视图中,我没有像在表格视图中那样获得确切的图像注释,而是从表格视图中获得随机图像作为注释,但标题名称与我想要的相同。

这是我的地图视图代码:

-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
(id <MKAnnotation>)annotation {
   pinView = nil;
if(annotation != mapview.userLocation) 
{

    static NSString *defaultPinID = @"defaultPinID";
    pinView = (MKAnnotationView *)[mapview dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
    if ( pinView == nil ) pinView = [[[MKAnnotationView alloc]
                                      initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];


    AddressInfo *address = [addressArray objectAtIndex:x];
NSString *dotstr=[NSString stringWithFormat:@"%@",address.category];
    NSString *dotstr1=@"0";
    if([dotstr isEqualToString:dotstr1])
    {
        NSLog(@"string 0 is %@",dotstr1);
        pinView.image=[UIImage imageNamed:@"greyDot.png"]; 
        NSLog(@"coming here 0");
    }
    NSString *dotstr2=@"10";
    if([dotstr isEqualToString:dotstr2])
    {
        NSLog(@"string 10 is %@",dotstr2);
        pinView.image=[UIImage imageNamed:@"blackDot.png"]; 
        NSLog(@"coming here 10");
    }
    NSString *dotstr3=@"20";
    if([dotstr isEqualToString:dotstr3])
    {
        NSLog(@"string 20 is %@",dotstr3);
        pinView.image=[UIImage imageNamed:@"greendot.png"];
        NSLog(@"coming here 20");
    }

    NSString *dotstr4=@"30";
    if([dotstr isEqualToString:dotstr4])
    {
        NSLog(@"string 30 is %@",dotstr4);
        pinView.image=[UIImage imageNamed:@"blueDot.png"];
        NSLog(@"coming here 30");
    }
    NSString *dotstr5=@"1";
    if([dotstr isEqualToString:dotstr5])
    {
        NSLog(@"string defau is %@",dotstr5);
        pinView.image=[UIImage imageNamed:@"greyDot.png"];
        NSLog(@"coming here default");
    }







    pinView.canShowCallout = YES;

    infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

    infoButton.tag=k;
    [infoButton addTarget:self action:@selector(pinLabelClicked:) forControlEvents:UIControlEventTouchUpInside];
    pinView.rightCalloutAccessoryView = infoButton;
    x++;


}
else {
    [mapview.userLocation setTitle:@"I am here"];
}

return pinView;


}

在第一个屏幕中,第一行包含每行左侧的蓝色图像我试图在地图视图中显示相同但在我的地图视图中蓝色注释显示灰色图像标题。有谁知道如何做到这一点。任何教程或示例代码?

4

1 回答 1

0

检查此框架https://github.com/jacobjennings/JJMapCallout

我在我的一个项目中使用它,效果很好。还在这里这里查看讨论

于 2012-08-07T09:32:05.620 回答