gpt4 book ai didi

ios - MKMapView 显示 DetailView - 如何进行转场

转载 作者:行者123 更新时间:2023-11-29 04:30:56 26 4
gpt4 key购买 nike

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

#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 属性,它唯一标识用户刚刚点击的标注。

关于ios - MKMapView 显示 DetailView - 如何进行转场,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11741334/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com