【发布时间】:2015-07-08 15:27:37
【问题描述】:
我有一个 MKMapView,我从一个数组中放置了一些引脚。每个地图图钉都有一个 MKAnnotationView 链接到一个 segue 和另一个控制器。
所有这些现在都运行良好,但我看不到如何通过 MKAnnotationView 将变量传递给 segue。
我可以传递字符串或整数,因为我可以将用户名作为字符串传递,或者传递数组的 id 并在 segue 之后的第二个视图控制器中使用它。
我用于循环遍历我的数组、删除引脚、添加注释、然后调用 segue 的工作代码如下。
这一切都很好,填充地图,删除垃圾箱,注释工作并链接到新的segue。这一切都很完美!
我只需要能够将变量从映射引脚数组传递到第二个视图控制器 segue。
- (void)loadMapPins {
for (int i=0; i<maparray.count; i++){
Location *item = _feedItems1[i];
CLLocationCoordinate2D myCoordinate = {[item.latitude doubleValue], [item.longitude doubleValue]};
MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
point.coordinate = myCoordinate;
point.title = item.firstname;
point.subtitle = [NSString stringWithFormat: @"%@", item.username];
[self.mapView addAnnotation:point];
}
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation {
if (annotation == self.mapView.userLocation) return nil;
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKPinAnnotationView* customPin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];
customPin.pinColor = MKPinAnnotationColorRed;
customPin.animatesDrop = YES;
customPin.canShowCallout = YES;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];
customPin.rightCalloutAccessoryView = rightButton;
return customPin;
}
- (IBAction)showDetails:(id)sender {
[self performSegueWithIdentifier:@"showProfileFromMap" sender:self];
}
【问题讨论】:
标签: objective-c mkmapview mkannotationview