【发布时间】:2015-08-27 17:50:14
【问题描述】:
我有一个从 VC1 到 VC2 的导航控制器。在 VC2 中,我有一个 mapkit 视图。在 VC2 用户中搜索位置。当用户单击任何注释时,它将返回到 VC1。现在我也想将注释中的地址发送回 VC1。换句话说,我想将数据从 VC2 传递到 VC1。我见过放松赛格。正如我在教程中看到的那样,我需要 Ctrl+拖动该项目才能退出。我的问题是我无权访问该元素。这个触发回到 VC1 的元素是动态的。
如果有人可以给我一个以编程方式执行此操作或任何其他建议的示例,我将不胜感激。
**EDIT**
This element is an annotation, which is dynamic.
- (IBAction)searchLocation:(id)sender {
// Create and initialize a search request object.
MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc] init];
request.naturalLanguageQuery = _nameLocation.text;
request.region = _mapview.region;
// Create and initialize a search object.
MKLocalSearch *search = [[MKLocalSearch alloc] initWithRequest:request];
// Start the search and display the results as annotations on the map.
[search startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error)
{
NSMutableArray *placemarks = [NSMutableArray array];
for (MKMapItem *item in response.mapItems) {
[placemarks addObject:item.placemark];
}
[_mapview removeAnnotations:[_mapview annotations]];
[_mapview showAnnotations:placemarks animated:NO];
}];
NSString* nameCurrLocation = _nameLocation.text;
NSLog(@"Location is %@",nameCurrLocation);
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinAnnotation = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = @"myPin";
pinAnnotation = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinAnnotation == nil )
pinAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID];
pinAnnotation.canShowCallout = YES;
//instatiate a detail-disclosure button and set it to appear on right side of annotation
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinAnnotation.rightCalloutAccessoryView = infoButton;
}
return pinAnnotation;
}
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
static NSString *defaultPinID = @"myPin";
MKPinAnnotationView *pinAnnotation = nil;
pinAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:view.annotation reuseIdentifier:defaultPinID];
NSLog(@"Text got clicked %@",view.annotation.title);
//From here I want to send view.annotation.title to VC1**
}
【问题讨论】:
-
"这个触发回到 VC1 的元素是动态的",这是什么意思?
-
@Poql Item 是 mapkitview 上的图钉。用户搜索位置后,他们会在地图上找到图钉。
标签: ios