[英]How do I access the the current annotation's class during “viewForAnnotation”?
[英]How do I access the current annotation's NSString when in “prepareForSegue”?
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
我如何在視圖中設置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;
}
}
現在,在使用標識符“ Details”訪問的第二個視圖控制器中,我有一個NSString,它將保存特定引腳的時間。 如何將當前引腳的時間NSString傳遞給下一個視圖的NSString?
注意:地圖上的不同時間只會設置多個圖釘,並且我嘗試使用情節提要將數據從注釋傳遞到iOS的詳細視圖iOS並嘗試使用
Pin *an = (Pin *)mapView.annotation;
但是它只允許我為mapView注釋使用數組
Pin *an = (Pin *)mapView.annotations;
請幫忙!
您可以通過注釋視圖的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.