如何在注释引脚上添加模型视图控制器以显示详细UI视图

时间:2011-10-17 06:12:09

标签: iphone annotations presentmodalviewcontroller

我想通过点击注释引脚来添加具有两个按钮和三个标签的详细信息视图。是否有任何教程或示例代码链接。我有搜索但只获得canShowCallout子标题,这是旧的方式。

编辑: - 我已经解析了URL然后成功条件我已经把这段代码放到了注释中。我应该在MKAnnotation视图中做些什么改变也告诉我.....

   for (int i = 0; i < [appDelegate.markers count]; i++)
{
    marker *aMarker = [appDelegate.markers objectAtIndex:i];
    location.latitude = [aMarker.lat floatValue];
    location.longitude =[aMarker.lng floatValue];
    AddressAnnotation *annobj = [[AddressAnnotation alloc]   initWithCoordinate:location];
    //[annobj setAnnotationType:AddressAnnotationTypeHettich];
    //annobj.title = aMarker.name;
    //annobj.subTitle = aMarker.address;
    [mapView addAnnotation:annobj];
    [annobj release];

            CLLocationCoordinate2D ausLoc = {location.latitude,location.longitude};                            
            //for zoom in the showroom results region
    MKCoordinateSpan ausSpan = MKCoordinateSpanMake(0.108889, 0.169922);
    MKCoordinateRegion ausRegion = MKCoordinateRegionMake(ausLoc, ausSpan);
    NSLog(@"No Errors");
    mapView.region = ausRegion;



}

1 个答案:

答案 0 :(得分:0)

        indexRow = 0;
        mapAnnonations = [[[NSMutableArray alloc] init] retain];
        for (int i = indexRow; i<[lat ,longi count]; i++)
        {
            region.center.latitude = [[lat objectAtIndex:indexRow] floatValue];
            region.center.longitude = [[longi objectAtIndex:indexRow] floatValue];
            region.span.longitudeDelta = 0.04f;
            region.span.latitudeDelta = 0.04f;

            [mymapView setRegion:region animated:YES];

            coordinate.latitude = [[lat objectAtIndex:indexRow] floatValue];
            coordinate.longitude = [[longi objectAtIndex:indexRow]floatValue];

            NSLog(@"Latitude & Longitude:---->%f,%f",coordinate.latitude,coordinate.longitude);

            mapAnnotation = [[AllMapAnnotation alloc] initWithCoordinate:coordinate]; 
            NSString *title = [[[resData valueForKey:@"name"] mutableCopy] objectAtIndex:indexRow];
            NSString *titleStr = [title stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
            NSLog(@"Pin Title:--->%@",titleStr);
            [mapAnnotation setTitle:titleStr];

            //[mapAnnotation setSubtitle:[NSString stringWithFormat:@"Ph: %@",pantries.phone]];
            mapAnnotation.coordinate = region.center; 
            [mapAnnonations insertObject:mapAnnotation atIndex:indexRow];
            [mymapView addAnnotations:mapAnnonations];
            //[mymapView addAnnotation:mapAnnotation];
            indexRow+= 1;
        }


-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation 
{
    MKPinAnnotationView *pinView = nil; 
    if(annotation!= mymapView.userLocation) 
    {
        static NSString *defaultPinID = @"pantryIdentifier";
        pinView = (MKPinAnnotationView *)[mymapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if ( pinView == nil ) pinView = [[[MKPinAnnotationView alloc]
                                          initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];

        pinView.pinColor = MKPinAnnotationColorGreen; 
        pinView.canShowCallout = YES;
        pinView.animatesDrop = YES;


        NSInteger annotationValue = [mapAnnonations indexOfObject:annotation];
        NSLog(@"Annotation Value:--->%d",annotationValue);

        rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
        rightButton.frame = CGRectMake(40, 5, 20, 22);

        [rightButton setBackgroundImage:[UIImage imageNamed:@"listtab_arrow.png"] forState:UIControlStateNormal];

        rightButton.tag = annotationValue;      
        [rightButton addTarget:self action:@selector(showDetails:)
                  forControlEvents:UIControlEventTouchUpInside];
        pinView.rightCalloutAccessoryView = rightButton;


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


    return pinView;

}

- (IBAction)showDetails:(UIView *)sender
{
    NSInteger selectedIndex = sender.tag;

    list = [[ListView alloc] initWithNibName:@"ListView" bundle:nil];
    details = [[resData valueForKey:@"reference"] mutableCopy];
    NSLog(@"Reference:--->%@",details);
        list.refernceIndex =  [NSString stringWithFormat:@"%@",[details objectAtIndex:selectedIndex]];

        [appDelegate.navigationController pushViewController:list animated:YES];

}