我尝试使用segue上的注释标题更新下一个视图中的标签,我不知道该怎么做,但正在研究这个问题。任何建议或是否需要在创建注释的地方完成?
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"pushShare"])
{
ShareViewController *vc = (ShareViewController *)segue.destinationViewController;
[vc fromLabel.text = StartAnnotation.title];
}
}
更新 单击按钮时会创建注释,在用户位置放置引脚并且注释标题显示地址,Iv尝试使用标题在同一视图中更新标签但是也遇到问题。
用于创建注释的代码
CLLocationCoordinate2D theCoordinate = {_map.userLocation.location.coordinate.latitude,_map.userLocation.location.coordinate.longitude};
CLLocation *currentLocation = [[CLLocation alloc]
initWithLatitude:_map.userLocation.location.coordinate.latitude
longitude:_map.userLocation.location.coordinate.longitude];
NSLog(@"self.geocoder=%@", self.geocoder);
[self.geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemark, NSError *error) {
NSString *address = @"Address unknown";
NSLog(@"geocoder error=%@", error);
if (placemark.count > 0)
{
CLPlacemark *topResult = [placemark objectAtIndex:0];
address = [NSString stringWithFormat:@"%@ %@ %@ %@", topResult.subThoroughfare, topResult.thoroughfare, topResult.subLocality, topResult.locality];
}
StartAnnotation *startPoint = [[StartAnnotation alloc]init];
startPoint.coordinate = theCoordinate;
startPoint.title = address;
startPoint.subtitle = @"Start Point";
[self.map addAnnotation:startPoint];
[self.map selectAnnotation:startPoint animated:YES];
}];
//e.g. fromLabel.text = StartAnnotation.title;
答案 0 :(得分:0)
您可以使用 didSelectAnnotationView
来检测用户何时点击 MKAnnotationView
,如下例所示:
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
[mapView deselectAnnotation:view.annotation animated:YES];
[self performSegueWithIdentifier:YOUR_SEGUE_ID
sender:view];
}
然后在 prepareForSegue
中提取注释的标题并使用它:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:YOUR_SEGUE_ID])
{
UIView *annotationView = (UIView *)sender;
ShareViewController *vc = (ShareViewController *)segue.destinationViewController;
vc.textToSetOnTheLabel = annotationView.annotation.title;
}
}