title: iPhone App, Mapkit different rightbutton view per annotation
body: <p>New to Objective C and IOS Development so hope someone can help. Ive got an app working with Mapkit. Each annotation has a callout and a right button that loads a new view. My issue is that the view that loads is the same for all annotations and I need it to be unique.</p>
  
  <p>Heres the .m </p>
  
  <pre><code>#import "CoffeeViewController.h"
  #import &lt;MapKit/MapKit.h&gt;
  #import "annotation.h"
  #import "Options.h"
  
  @implementation CoffeeViewController
  @synthesize mapView,options;
  
  - (void)didReceiveMemoryWarning
  {
      // Releases the view if it doesn't have a superview.
      [super didReceiveMemoryWarning];
  
      // Release any cached data, images, etc that aren't in use.
  }
  
  - (void) gotoLocation {
      //start by default in london
      MKCoordinateRegion newRegion;
      newRegion.center.latitude = 51.519853;
      newRegion.center.longitude = -0.122223;
      newRegion.span.latitudeDelta = 0.112872;
      newRegion.span.longitudeDelta = 0.109863;
  
      [self.mapView setRegion:newRegion animated:YES];
  
  }
  
  // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
  - (void)viewDidLoad
  {
      [super viewDidLoad];
      CLLocation *userLoc = mapView.userLocation.location;
      CLLocationCoordinate2D userCoordinate = userLoc.coordinate;
      NSLog(@"user latitude = %f",userCoordinate.latitude);
      NSLog(@"user longitude = %f",userCoordinate.longitude);
      mapView.delegate=self;
  
      NSMutableArray* annotations=[[NSMutableArray alloc] init];
  
      CLLocationCoordinate2D theCoordinate1;
      theCoordinate1.latitude = 51.465264;
      theCoordinate1.longitude = -0.126858;
  
      CLLocationCoordinate2D theCoordinate2;
      theCoordinate2.latitude = 51.549324;
      theCoordinate2.longitude = -0.132866;
  
      annotation* myAnnotation1=[[annotation alloc] init];
  
      myAnnotation1.coordinate=theCoordinate1;
      myAnnotation1.title=@"Monmouth Coffee Company";
      myAnnotation1.subtitle=@"Excellent Coffee";
  
      annotation* myAnnotation2=[[annotation alloc] init];
  
      myAnnotation2.coordinate=theCoordinate2;
      myAnnotation2.title=@"L J Coffee House";
      myAnnotation2.subtitle=@"Good Times";
  
      [mapView addAnnotation:myAnnotation1];
      [mapView addAnnotation:myAnnotation2];
  
      [annotations addObject:myAnnotation1];
      [annotations addObject:myAnnotation2];
  
      NSLog(@"%d",[annotations count]);
  
      MKMapRect flyTo = MKMapRectNull;
      for (id &lt;MKAnnotation&gt; annotation in annotations) {
          NSLog(@"fly to on");
          MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate);
          MKMapRect pointRect = MKMapRectMake(annotationPoint.x,annotationPoint.y, 0,0);
  
                                              if (MKMapRectIsNull(flyTo)) {
                                                  flyTo = pointRect;
                                              } else {
                                                  flyTo = MKMapRectUnion(flyTo, pointRect);
                                              }
  
                                              }
  
                                              mapView.visibleMapRect = flyTo;
  
  
                                              }
  
  
  
  - (void)viewDidUnload
  {
      [super viewDidUnload];
      // Release any retained subviews of the main view.
      // e.g. self.myOutlet = nil;
  }
  
  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  {
      // Return YES for supported orientations
      return (interfaceOrientation == UIInterfaceOrientationPortrait);
  
  }
  
  - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id&lt;MKAnnotation&gt;)annotation
  {
      NSLog(@"Welcome to the map view annotation");
      if ([annotation isKindOfClass:[MKUserLocation class]])
          return nil;
  
      static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
      MKPinAnnotationView* pinView = [[[MKPinAnnotationView alloc]
                                        initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];
      pinView.image=[UIImage imageNamed:@"coffeeicon.png"];
      pinView.canShowCallout=YES;
  
      UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
      [rightButton setTitle:annotation.title forState:UIControlStateNormal];
      [rightButton addTarget:self action:@selector(SwitchView:)
            forControlEvents:UIControlEventTouchUpInside];
      pinView.rightCalloutAccessoryView = rightButton;
  
      UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"coffeeicon.png"]];
      pinView.leftCalloutAccessoryView = profileIconView;
      [profileIconView release];
      return pinView;
  
  }
  
  - (IBAction)SwitchView:(id)sender{
  
      NSLog(@"Annotation Click");
  
      Options *OptionsView = [[Options alloc] initWithNibName:nil bundle:nil];
      [self presentModalViewController:OptionsView animated:YES];
  }
  
  -(void)dealloc {
      [super dealloc];
  }
  
  @end
  </code></pre>