2010-01-14 11 views
5

के लिए एक बटन प्रदर्शित मैं एक MKMapView स्रोत कोड की इन पंक्तियों के साथ लागू किया (मेरे स्थान एक नीले रंग की गोली, एक दूसरे के बैंगनी पिन कर रहे हैं):MKMapView -> मेरे स्थान

- (MKAnnotationView *)mapView:(MKMapView *)mapViewLocal viewForAnnotation:(id <MKAnnotation>)annotation { 
    if (annotation == mapViewLocal.userLocation) { 
     mapViewLocal.userLocation.title = @"Test"; 
     [mapViewLocal setRegion:MKCoordinateRegionMakeWithDistance(mapViewLocal.userLocation.coordinate, 1000, 1000) animated:YES]; 
     return nil; 
    } 

    MKPinAnnotationView *pinView = (MKPinAnnotationView*)[mapViewLocal dequeueReusableAnnotationViewWithIdentifier:@"Pin"]; 
     if(pinView == nil) { 
      pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"] autorelease]; 
      pinView.pinColor = MKPinAnnotationColorPurple; 
      pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
      pinView.animatesDrop = NO; 
      pinView.canShowCallout = YES; 
     } else { 
      pinView.annotation = annotation; 
     } 
     return pinView; 
    } 

बैंगनी पिन है एक विस्तार प्रकटीकरण बटन, लेकिन मेरी एनोटेशन में एक नहीं है। मैं ऐसा बटन कैसे सेट कर सकता हूं? , क्योंकि मैं एक अलग से निपटने की जरूरत है

-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control 

मैं अपने स्थान और अन्य सभी एक के बीच में कैसे फ़र्क हो सकता है:

और वह तरीका है, जहां मैं किसी चीज़ के लिए एक बटन pressd है कर सकते हैं। क्या कोई और प्रतिनिधि है या क्या मुझे कुछ प्रकार का खंड बनाना है?

उत्तर

4

AddressAnnotation *myAnnotation = [[AddressAnnotation alloc] initWithCoordinate:currentLocation]; 
       myAnnotation.title = @"You are here"; 
       [self.mapView addAnnotation:myAnnotation]; 

और फिर

कुछ की तरह

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
      // try to dequeue an existing pin view first 
     static NSString* annotationIdentifier = @"annotationIdentifier"; 

     NSString *titlestr = annotation.title; 

     MKPinAnnotationView* pinView = (MKPinAnnotationView *) 
     [mapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier]; 
    MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc] 
              initWithAnnotation:annotation reuseIdentifier:nil] autorelease]; 
     if (!pinView) 
     { 
      // if an existing pin view was not available, create one 
      // MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc] 
                //initWithAnnotation:annotation reuseIdentifier:annotationIdentifier] autorelease]; 
      if([titlestr isEqualToString:@"You are here"]) 
      { 
       customPinView.pinColor = MKPinAnnotationColorGreen; 
       NSLog(@"customPinView.pinColor = MKPinAnnotationColorGreen;"); 
      } 
      else{ 
       customPinView.pinColor = MKPinAnnotationColorPurple; 
       customPinView.selected = TRUE; 
       NSLog(@"customPinView.pinColor = MKPinAnnotationColorPurple;"); 
       UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
       [rightButton addTarget:self 
           action:@selector(ShowStoreDetail:) 
         forControlEvents:UIControlEventTouchUpInside]; 
       customPinView.rightCalloutAccessoryView = rightButton; 
      } 
      customPinView.animatesDrop = YES; 
      customPinView.canShowCallout = YES; 

      return customPinView; 
     } 
     else 
     { 
      pinView.annotation = annotation; 



      if([titlestr isEqualToString:@"You are here"]) 
      { 
       customPinView.pinColor = MKPinAnnotationColorPurple; 
       NSLog(@"customPinView.pinColor = MKPinAnnotationColorGreen;"); 
      } 
      else{ 
       customPinView.pinColor = MKPinAnnotationColorPurple; 
       customPinView.selected = TRUE; 
       NSLog(@"customPinView.pinColor = MKPinAnnotationColorPurple;"); 
       UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
       [rightButton addTarget:self 
           action:@selector(ShowStoreDetail:) 
         forControlEvents:UIControlEventTouchUpInside]; 
       customPinView.rightCalloutAccessoryView = rightButton; 
      } 


     } 
     return pinView; 

    return nil; 
} 
की तरह अपने didUpdateToLocation लिखने कुछ में