Questions about Figure 5.2 & Figure 5.13


#1

In figure 5.2, there’s a method mapView:didAddAnnotationViews: which I could not find throughout the Chapter. Any reason for that?

In figure 5.13, I’m quite confused about some arrows (pointers??) and classes which I couldn’t find in the Chapter.

  • What are the two ‘annotation’ pointed by MKAnnotationView? How about the ‘annotations’ and ‘subviews’ pointed by MKMapView?
  • Where were the class MKAnnotationView used in the example codes? How were they used?
  • Why did MKUserLocation also conform to MKAnnotation protocol? I can only find BNRMapPoint conforming to the protocol by stating @interface BNRMapPoint : NSObject .
  • And also the rectangles ‘subviews’ and ‘annotations’ point to.

Sorry for so many questions on it but i really cannot figure it out even though I’ve read through the Chapter for a few times and have completed the exercises.

Can someone help explain about that? Thanks!!!


#2

Whoops, good catch: the mapView:didAddAnnotationsViews: is another message that the MKMapView sends to its delegate. You can replace that with mapView:didUpdateUserLocation: and it should make more sense.

When an annotation is added to an MKMapView, an MKAnnotationView is automatically created and has its annotation property set to point at the annotation. This MKAnnotationView is added as a subview to the MKMapView. Both MKUserLocation and BNRMapPoint conform to MKAnnotation because that is what defines these objects as “annotations that can be added to a MKMapView.” Page 114 says this in another way.

The rectangles you see mean an instance of NSArray. Thus, MKMapView has an NSArray *subviews instance variable that has two MKAnnotationViews in it (the blue dot where the user is and the red pin where you have marked a location).