[英]How do I access the current annotation's NSString when in “prepareForSegue”?
Pin .h Pin .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
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];
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;
}
}
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. 现在,在使用标识符“ Details”访问的第二个视图控制器中,我有一个NSString,它将保存特定引脚的时间。 How can I pass the current pin's time NSString to the next view's NSString? 如何将当前引脚的时间NSString传递给下一个视图的NSString?
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 注意:地图上的不同时间只会设置多个图钉,并且我尝试使用情节提要将数据从注释传递到iOS的详细视图iOS并尝试使用
Pin *an = (Pin *)mapView.annotation;
but it only lets me used an array for the mapView annotation 但是它只允许我为mapView注释使用数组
Pin *an = (Pin *)mapView.annotations;
Please Help! 请帮忙!
You can access your annotation via the annotation
property of the annotation view and then pass this as the sender to performSegueWithIdentifier
like so 您可以通过注释视图的annotation
属性访问注释,然后将其作为发件人传递给performSegueWithIdentifier
如下所示
- (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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.