Instance Method

dequeueReusableAnnotationViewWithIdentifier:forAnnotation:

Returns a reusable annotation view using the specified identifier.

Declaration

- (MKAnnotationView *)dequeueReusableAnnotationViewWithIdentifier:(NSString *)identifier forAnnotation:(id<MKAnnotation>)annotation;

Parameters

identifier

A string identifying the annotation view to be created.

annotation

The annotation being displayed. This method automatically assigns this annotation object to the returned annotation view.

Return Value

An annotation view with the specified identifier.

Discussion

For performance reasons, you should reuse MKAnnotationView objects in your map views. As annotation views move offscreen, the map view moves them to an internally managed reuse queue. As new annotations move onscreen, and your code is prompted to provide a corresponding annotation view, use this method to dequeue an existing view. Dequeueing saves time and memory during performance-critical operations such as scrolling.

If an existing view cannot be dequeued, this method tries to create one from the specified identifier. For this to happen, you must have already registered an annotation view class using the registerClass:forAnnotationViewWithReuseIdentifier: method. If a class with the appropriate identifier has not been registered, this method throws an exception.

See Also

Creating Annotation Views

- registerClass:forAnnotationViewWithReuseIdentifier:

Registers an annotation view class that the map can create automatically.

- dequeueReusableAnnotationViewWithIdentifier:

Returns a reusable annotation view located by its identifier.

- viewForAnnotation:

Returns the annotation view associated with the specified annotation object, if any.

MKMapViewDefaultAnnotationViewReuseIdentifier

The default reuse identifier for your map's annotation views.

MKMapViewDefaultClusterAnnotationViewReuseIdentifier

The default reuse identifier for the annotation view representing a cluster of annotations.