0

I nearly followed this post. The viewcontroller will push via storyboard. Here the relevant code:
ViewController.m:

-(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;

and DetailViewController:

@interface DetailViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIImageView *branchImage;
@property (strong, nonatomic) IBOutlet UILabel *titleLabel;
@property (strong, nonatomic) IBOutlet UITextView *textView;

I think my mistake is in the calloutAccessoryControlTapped method but I dont know what is the real reason for this issue.

Community
  • 1
  • 1
CTSchmidt
  • 1,155
  • 3
  • 17
  • 30

2 Answers2

1

If you use a storyboard, can use prepareForSegue method and set within a class similarly as you have made.

I post a portion of code

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

if([segue.identifier isEqualToString:@"Brs"]){
    NSLog(@"segue %@ ",[segue identifier]);
    [segue.destinationViewController setPath:[ris_xml objectAtIndex:index_post-1] ];
    }
}

In this example I set attribute "Path" of next UIViewController only if his identifier is "Brs". For use this method is need set UIviewController identifier into storyboard right panel. Using this isn't need to instantiate new UIViewController if you have it in storyboard.

CTSchmidt
  • 1,155
  • 3
  • 17
  • 30
dpizzuto
  • 412
  • 1
  • 5
  • 14
0

I solved it by thinking about loading sequence.
All what to do is create temporary @properties

@interface DetailViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIImageView *branchImage;
@property (strong, nonatomic) IBOutlet UILabel *titleLabel;
@property (strong, nonatomic) IBOutlet UITextView *textView;
@property (nonatomic) NSString *titleTMP;        //added
@property (nonatomic) NSString *subtitleTMP;     //added

and do

-(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];
}

The DetailViewController:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    titleLabel.text = titleTMP;
    textView.text = subtitleTMP;

}
CTSchmidt
  • 1,155
  • 3
  • 17
  • 30