问题
i am trying to pull a map in my applcation with interface builder using MKMapView but for some reason its not showing up. Also i want to add some button to this view by clicking which i can browse a file existing in my iphone.
Please provide me with the detial description as i am new to this.
Thanks,
回答1:
You'll want to add an annotation to the map, then provide a custom view for it.
To add an annotation to the map, adopt the MKAnnotation protocol in one of your objects and set its coordinate property to the appropriate lat/lon location.
Next, you'll add the annotation to the map using MKMapView addAnnotation.
Set the map's delegate property to your view controller, then implement mapView:viewForAnnotation:
When this method gets called, return a MKAnnotationView for your annotation. Set the MKAnnotationView's image property to whatever image you want the annotation to use (an image of a button perhaps?).
You can implement mapView:didSelectAnnotationView: if you want to know when the annotation was selected.
You can also set a callout accessory button on the annotation using MKAnnotationView's leftCalloutAccessoryView and rightCalloutAccessoryView properties. If you do this, you can then respond when the user selects the callout button by implementing mapView:annotationView:calloutAccessoryControlTapped:.
回答2:
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
static NSString *AnnotationViewID = @"annotationViewID";
annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
if (annotationView == nil)
{
annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
}
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
annotationView.image = [UIImage imageNamed:@"s11.png"];
annotationView.annotation = annotation;
[annotationView setEnabled:YES];
[annotationView setCanShowCallout:YES];
return annotationView;
}
来源:https://stackoverflow.com/questions/3303919/how-to-put-a-button-on-a-map-in-iphone