MKMapView显示DetailView-如何进行排序 [英] MKMapView show DetailView - How to make a segue

查看:94
本文介绍了MKMapView显示DetailView-如何进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MapView,注释来自属性列表. 现在,我想在详细视图中查看更多数据. 不幸的是,我没有如何对Segue进行编程,以便可以显示数据. 我希望你明白我的意思.我的英语不太好 ... 我知道方法prepareforSegue中缺少一些内容. 我正在使用情节提要. 预先感谢您的帮助... 问候

I have a MapView, the annotations comes from a property list. Now I would like to see more data in the detail view. Unfortunately I do not how to program the Segue, so that data can be displayed. I hope you understand what I mean. My english is not so good ... I know that there is missing some in the method prepareforSegue. I am using storyboard. In advance thank you for your help ... regards

#import "MapViewNewController.h"
#import "MapViewAnnotation.h"
#import "SetCardController.h"



@interface MapViewNewController ()



@end

@implementation MapViewNewController 


@synthesize recipesDictionary = _recipesDictionary;

@synthesize mapView;
@synthesize locationManager;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}



- (void)viewDidLoad
{
    [super viewDidLoad];

    self.mapView.delegate = self;

    [self.mapView setShowsUserLocation:YES];


    MKCoordinateRegion newRegion ;
    newRegion.center.latitude = 50.080635;
    newRegion.center.longitude = 8.518717;
    newRegion.span.latitudeDelta = 15.5;
    newRegion.span.longitudeDelta = 15.5;
    [mapView setRegion:newRegion animated:YES];



    NSString *path = [[NSBundle mainBundle] pathForResource:@"Rezepte" ofType:@"plist"];
    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];
    NSArray *anns = [dict objectForKey:@"myRecipes"];
    for(int i = 0; i < [anns count]; i++) {
        float realLatitude = [[[anns objectAtIndex:i] objectForKey:@"latitude"] floatValue];
        float realLongitude = [[[anns objectAtIndex:i] objectForKey:@"longitude"] floatValue];

        MapViewAnnotation *myAnnotation = [[MapViewAnnotation alloc] init];
        CLLocationCoordinate2D theCoordinate;
        theCoordinate.latitude = realLatitude;
        theCoordinate.longitude = realLongitude;
        myAnnotation.coordinate = theCoordinate;
        myAnnotation.title = [[anns objectAtIndex:i] objectForKey:@"blogname"];
        myAnnotation.subtitle = [[anns objectAtIndex:i] objectForKey:@"blogger"];
        [mapView addAnnotation:myAnnotation];


    }      

}


-(MKAnnotationView *)mapView:(MKMapView *)view viewForAnnotation:(id<MKAnnotation>)annotation {
    MKPinAnnotationView *pin = nil;

    if ([annotation isKindOfClass:[MapViewAnnotation class]]) {
        NSString *pinIdentifier = @"myPin";


        pin = (MKPinAnnotationView*)[view dequeueReusableAnnotationViewWithIdentifier:pinIdentifier];
        if (!pin) {


            pin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pinIdentifier];

            pin.image = [UIImage imageNamed:@"pin2.png"];
            pin.canShowCallout = YES;

            pin.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];


        }
            }

    return pin;
}



//if Button pressed
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{

     [self performSegueWithIdentifier:@"showPinDetails" sender:self];




    }

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if ([segue.identifier isEqualToString:@"showPinDetails"]) {

       // SetCardController *scc = [segue destinationViewController];


    }
}

推荐答案

当您在annotationView:view内部的标注中performSegueWithIdentifier:sender时,发件人可以是view.annotation属性,该属性唯一地标识用户刚刚点击的标注

When you performSegueWithIdentifier:sender from a callout inside annotationView:view, the sender can be the view.annotation property, which uniquely identifies the callout that the user just tapped.

这篇关于MKMapView显示DetailView-如何进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆