如何在地图套件中获取pin弹出消息动态在iphone中

时间:2011-08-05 13:30:43

标签: iphone mkmapview

我有一项任务是使用asp.net的地图套件和网络服务来开发应用程序。

我的问题是当我从网络服务获得位置时。根据该位置,引脚也设置在它的位置。

但我的问题是我已经弹出了它的针脚。当用户点击它将显示弹出窗口时,它正在工作。但是针上的弹出不起作用。我已经包含了弹出引脚和引脚的所有相关代码。但是当我点击那个针时,它无法正常工作。

我也在添加代码以显示我给出的地图和消息上的图钉。

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
    NSLog(@"Controll comes here");

    if (annotation == mapView.userLocation) 
        return nil;

    MKPinAnnotationView *pin = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier: @"asdf"];

    if (pin == nil)
        pin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier: @"asdf"] autorelease];

    else

    pin.annotation = annotation;
    pin.userInteractionEnabled = YES;
    UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    [disclosureButton setFrame:CGRectMake(0, 0, 30, 30)];

    pin.rightCalloutAccessoryView = disclosureButton;
    pin.pinColor = MKPinAnnotationColorRed;
    pin.animatesDrop = YES;
    [pin setEnabled:YES];
    [pin setCanShowCallout:YES];
    return pin;

}

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    NSString *strTitle = [NSString stringWithFormat:@"%@",[lines objectAtIndex:i]];
    NSMutableDictionary *d;
    NSMutableArray *temp=[NSArray arrayWithArray:lat];

    //  NSArray *temp=[NSArray arrayWithArray:[NSArray arrayWithArray:[reports objectAtIndex:0]]];
    for (int k = 0; k< i -1; k++)
    {
        d = (NSMutableDictionary*)[temp objectAtIndex:k];
        NSString *strAddress = [NSString stringWithFormat:@"%@",[d valueForKey:@"comments"]];

        if([strAddress isEqualToString:strTitle]) {
            [self presentModalViewController:self.nxtDetailsVCtr animated:YES];
            [self.nxtDetailsVCtr.lblDetail setText:strAddress];     
            break;
        }


    }
}

1 个答案:

答案 0 :(得分:0)

为此你需要为此实现以下代码

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    NSString *strTitle = [NSString stringWithFormat:@"%@",[view.annotation title]];
    NSMutableDictionary *d;
    NSArray *temp=[NSArray arrayWithArray:[NSArray arrayWithArray:[reports objectAtIndex:0]]];
    for (int i = 0; i<[temp count]; i++)
    {
        d = (NSMutableDictionary*)[temp objectAtIndex:i];
        NSString *strAddress = [NSString stringWithFormat:@"%@",[d valueForKey:@"comments"]];

            if([strAddress isEqualToString:strTitle])
            {
                if(!nxtDetails){
                   nxtDetails=[[MyCityDetails alloc] initWithNibName:@"MyCityDetails" bundle:nil];
                }
                NSLog(@"%@",[dForAnnotation valueForKey:@"report_types"]);
                nxtDetails.dForAnnotation= dForAnnotation;
nxtDetails.arForAnnotation=d;
                [self.navigationController pushViewController:nxtDetails animated:YES];
            }

    }
}