ios - 如何在 UINavigationBar 中将信息从 child 发送到 parent (Unwind segue 问题)?

标签 ios

我有一个从 VC1 到 VC2 的导航 Controller 。在 VC2 中,我有一个 mapkit View 。在 VC2 用户搜索位置。当用户单击任何注释时,它将返回到 VC1。现在我也想将注释中的地址发回给 VC1。换句话说,我想将数据从 VC2 传递到 VC1。我已经看到了 unwind segue。正如我在教程中看到的那样,我需要按住 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**
}

最佳答案

您可以使用代码执行转场。

Ctrl + 将您的 VC1 拖到 VC2。在您的 segue 处提供一个标识符。

在代码中,检测 pin 何时被点击,然后使用 Controller 的 performSegueWithIdentifier:sender: 方法推送 Controller ,并覆盖 prepareForSegue:sender: 方法处理它 `

关于ios - 如何在 UINavigationBar 中将信息从 child 发送到 parent (Unwind segue 问题)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32245395/

相关文章:

ios - 需要帮助关闭 iOS 中的电子邮件编辑器屏幕

ios - 函数在 Storyboard 加载之前开始

ios - 尝试转换场景时无法将 UIView 的值转换为 SCNView

ios - 如何在 Swift 3 的基类中实例化对象

ios - PFObject 在 Xcode 6.0.1、Yosemite GM3 中没有名为 'saveInBackground' 的成员

ios - 苹果的AVCamera夜间模式

ios - 如何在 iOS 上使用 PhoneGap 检测是否调用电话

iphone - 应用程序不在 ios 7 的后台运行

objective-c - iOS 5 JSON 到 tableView 错误

ios - iBeacons 问题 : Did enter region triggers multiple times