我幾乎遵循這個post。視圖控制器將通過故事板推送。這裏的相關代碼:
ViewController.m:在ViewController之間傳遞地圖數據
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(@"%@", view.annotation.title);
MapPoint *annView = view.annotation;
DetailViewController *dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];
dvc.title = @"my own Details";
dvc.titleTMP = annView.title;
dvc.subtitleTMP = annView.subtitle;
[self.navigationController pushViewController:dvc animated:YES];
}
MapPoint.h:
@interface MapPoint : NSObject <MKAnnotation>
{
NSString *_title;
NSString *_subtitle;
CLLocationCoordinate2D _coordinate;
UIImage *_storeImage;
}
@property (copy) NSString *title;
@property (copy) NSString *subtitle;
@property (nonatomic, readonly) UIImage *storeImage;
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
- (id)initWithTitle:(NSString*)title subtitle:(NSString*)subtitle coordinate:(CLLocationCoordinate2D)coordinate storeImage:(UIImage*)storeImage;
和DetailViewController:
@interface DetailViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIImageView *branchImage;
@property (strong, nonatomic) IBOutlet UILabel *titleLabel;
@property (strong, nonatomic) IBOutlet UITextView *textView;
我覺得我的錯誤是在calloutAccessoryControlTapped方法但我不知道這個問題的真正原因是什麼。