I have eventually succeeded with getting the index for the annotation clicked on at callOutAccecoryControlTapped-method. :) I have made a custom annotation class called Annotation (Annnotation *ann) which I fill with values from my db at parse.com. But now I don't know how to pass the values on to my next view LAOpeningHoursViewController? I can see all the values when I am debugging and *ann (se code) has for example: ann.cname="Olles cafe" etc. So that is good.
I pass the whole ann-object on to my next view. But I don't know how to get for example ann.cname on to my 'self.myLabel.text'. I show you the code:
If you have the kindness to answer me, please explain very well because I am a beginner. Best is if you could have the trouble writing a code-snippet here… ;)
This is some code of the first view:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"pinView"];
if (!pinView) {
pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pinView"];
pinView.pinColor = MKPinAnnotationColorRed;
pinView.animatesDrop = YES;
pinView.canShowCallout = YES;
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinView.rightCalloutAccessoryView = rightButton;
} else {
pinView.annotation = annotation;
}
return pinView;
}
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
Annotation *ann = [[mapView selectedAnnotations] objectAtIndex:0];
NSLog(@"ann.subtitle = %@", ann.subtitle);
NSLog(@"ann.cid = %@", ann.cid);
NSLog(@"ann.cstr = %@", ann.cstr);
NSLog(@"ann.cname = %@", ann.cname);
//this works fine, I get all the values
[self performSegueWithIdentifier: @"openingHours" sender:ann];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"openingHours"]) {
LAOpeningHoursViewController *secondView = (LAOpeningHoursViewController*)segue.destinationViewController;
//PFObject *tempObject = [[myMapView selectedAnnotations] objectAtIndex:0];
Annotation *ann = (id)sender;
//Here is the problem: What to pass? I want to pass for example ann.cname that is declared in my custom annotation
//Both 'ann' and 'tempObject' has the right values for cname but I dont know how to pass it to the next view
secondView.myLabel.text = self.stringToPass;
//secondView.myLabel.text = ann.cname;
}
}
And here is the code from the second view called LAOpeningHoursViewController, that should receive the data:
- (void)viewDidLoad
{
[super viewDidLoad];
self.myLabel.text = ann.cname;
//recieving an error-code… of course
}
declared in LAOpeningHoursViewController.h as this
@property (strong, nonatomic) IBOutlet UILabel *myLabel;
@property (strong, nonatomic) NSString *textContent;
and finally, here is my Annotation.h-file where cname is the one that should go to 'myLabel'
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface Annotation : NSObject <MKAnnotation>
@property(nonatomic, assign) CLLocationCoordinate2D coordinate;
@property(nonatomic, copy)NSString *title;
@property(nonatomic, copy)NSString *subtitle;
@property(nonatomic, copy)UIButton *rightButton;
@property(nonatomic, retain)NSString *cid;
@property(nonatomic, retain)NSString *cname;
@property(nonatomic, retain)NSString *ctel;
@property(nonatomic, retain)NSString *cstr;
@property(nonatomic, retain)NSString *cmon;
@property(nonatomic, retain)NSString *ctue;
@property(nonatomic, retain)NSString *cwed;
@property(nonatomic, retain)NSString *passedId;
@property(nonatomic, retain)NSString *objectId;
@end