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 *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. How can I pass the current pin's time NSString to the next view's 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
Pin *an = (Pin *)mapView.annotation;
but it only lets me used an array for the mapView annotation
Pin *an = (Pin *)mapView.annotations;
Please Help!