我如何访问当前标注的的NSString当" prepareForSegue"? [英] How do I access the current annotation's NSString when in "prepareForSegue"?

查看:121
本文介绍了我如何访问当前标注的的NSString当" prepareForSegue"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

引脚的.h

#import <Foundation/Foundation.h>
@import MapKit;

@interface Pin : NSObject <MKAnnotation> {

NSString *time;
CLLocationCoordinate2D coordinate;
}

@property (nonatomic, copy)   NSString *time;
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;

@end

Pin.m

#import "Pin.h"

@implementation Pin

@synthesize coordinate;
@synthesize time;
@end

我如何设置我的脚在视图

How I set my Pin in the view

Pin *newPin = [[Pin alloc]init];
            newPin.coordinate = userCoordinate;

    NSDate *currentTime = [NSDate date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"MM-DD-yyy hh:mm a"];
    NSString *resultString = [dateFormatter stringFromDate: currentTime];
    newPin.time = resultString;
    [self.mapView addAnnotation:newPin];

当我$发生了什么p $ PSS标注

What Happens when I press the callout

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    [self performSegueWithIdentifier:@"Details" sender:view];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
      if ([segue.identifier isEqualToString:@"Details"])
     {
        InfoViewController *vc = segue.destinationViewController;
     }
}

现在在与标识符详细信息访问的第二个视图控制器,我有一个的NSString,将持有的具体引脚的时间。
如何传递当前针的时候的NSString到下一个视图的NSString?

Now in the second view controller that is accessed with the identifier "Details", I have a NSString that will hold the time of the specific pin. How can I pass the current pin's time NSString to the next view's NSString?

注:有,但会设定在地图上的不同时间多个引脚,我曾尝试<一个href=\"http://stackoverflow.com/questions/20986571/passing-data-from-annotations-to-detail-view-ios-using-storyboard\">Passing用故事板和注释详细信息视图的iOS数据试图用

Note: There will but multiple pins set at different times on the map and I have tried Passing data from annotations to detail view iOS using storyboard and tried to use

Pin *an = (Pin *)mapView.annotation;

但它只是让我用一个数组的MapView注释

but it only lets me used an array for the mapView annotation

Pin *an = (Pin *)mapView.annotations;

请帮助!

推荐答案

您可以通过注释访问您的注解注释视图属性,然后通过这个作为发件人到 performSegueWithIdentifier 像这样

You can access your annotation via the annotation property of the annotation view and then pass this as the sender to performSegueWithIdentifier like so

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    [self performSegueWithIdentifier:@"Details" sender:view.annotation];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
      if ([segue.identifier isEqualToString:@"Details"])
     {
        Pin *myPin=(Pin *)sender;
        InfoViewController *vc = segue.destinationViewController;
        vc.time=myPin.time;
     }
}

这篇关于我如何访问当前标注的的NSString当&QUOT; prepareForSegue&QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆