如何在注释 Pin 上添加 ModelView 控制器以显示详细 UI 视图

发布于 2024-12-10 10:14:35 字数 1090 浏览 0 评论 0原文

我想通过点击注释图钉来添加具有两个按钮和三个信息标签的详细视图。是否有任何教程或示例代码链接。我进行了搜索,但只得到了 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;



}

I want to add detail view having Two buttons and three labels for information by taping on annotation pin. Is there any tutorial or sample code link for this. I have search but get only canShowCallout sub title which is old ways.

Edited:- I have parsed URL then on success condition I have put this code to put annotation. What should I make change in MKAnnotation view also tell me.....

   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;



}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

好倦 2024-12-17 10:14:35
        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];

}
        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];

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文