【发布时间】:2014-08-18 18:53:03
【问题描述】:
引脚.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
如何在视图中设置我的 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];
当我按下标注时会发生什么
- (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?
注意:地图上会在不同时间设置多个图钉,我尝试过Passing data from annotations to detail view iOS using storyboard并尝试使用
Pin *an = (Pin *)mapView.annotation;
但它只允许我使用一个数组作为 mapView 注释
Pin *an = (Pin *)mapView.annotations;
请帮忙!
【问题讨论】:
标签: ios objective-c annotations segue