0

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

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


    }
}
4

3 回答 3

1

当你performSegueWithIdentifier:sender从一个 callout 里面annotationView:view时, sender 可以是这个view.annotation属性,它唯一地标识了用户刚刚点击的 callout。

于 2013-05-18T20:52:17.800 回答
0

以上两个答案有帮助,但不能帮助您识别我假设是您的 p-list 的一部分的唯一引脚详细信息。

所有视图都继承了标签的属性。它可以使用它来保存 pin 索引(或键),因此将其传递给目标 View Controller 以唯一标识您持有的数据。

由于调用视图中的按钮继承自视图,因此您可以对其进行标记,并在其在方法 didselectAnnotationView 中处于活动状态时传递索引。使用的 if 语句取消选择用户位置引脚。

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{

if (![(PointAnnotation *)view.annotation isKindOfClass:[MKUserLocation class]])
{
    PointAnnotation *myAnn = (PointAnnotation *)view.annotation;

    detailButton.tag = myAnn.pinIndex;
    NSLog (@"Pinindex = %d", myAnn.pinIndex);
}



}

detailButton.tag 现在可以用作 segue 选择中的参数。

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Post data to destination VC

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


    ClubsMasterData *current = [[ClubsMasterxmlParser ClubsMasterDatas] objectAtIndex:detailButton.tag];


    ClubsDetailViewController *DVC = [[ClubsDetailViewController alloc] init];
    DVC = [segue destinationViewController];


    DVC.linkURL =  current.linkURL;
    DVC.distance = current.distance;

}
}

这里我索引了一个 Array 而不是 Plist,但原理是一样的。

于 2013-07-15T15:36:40.883 回答
0

我相信您没有在 Interface Builder 中设置 Segue 的标识符。我试过你的代码,它对我有用(Xcode 4.4 iOS 5.1 SDK)

于 2012-08-09T02:30:35.943 回答