Of course the extra credit part may be another story... should I
bother?!
Anyway, I struggled a bit with the last bit - adding annotations to
the map view which contain the photo title, user name and a disclosure
button which displays the photo.
According to the assignment walkthrough: "you can get all of the
expected functionality using just the following:
- MKMapView - MKMapViewDelegate - MKPlacemark"
I've got it working but I presume I haven't done it the 'right' way as
I couldn't get it to work with MKPlacemark! In the end I created my
own implementation of the MKAnnotation protocol, which is initialized
with a Photo and retrieves the required details from it. Any advice on
how to display the photo title and username using MKPlacemark would be
appreciated. I figure I could have sub-classed it but that seemed a)
naff and b) as much work as implementing my own MKPhotoAnnotation
which has the photo in it ready to display when the disclosure button
is pressed.
I also found it really tricky to get the disclosure button displayed.
I'm not sure if I was missing something obvious?
Vicki
Overall steps for me were:
1) Create a class PhotoAnnotation which implements MKAnnotation
2) Create a subclass of UIViewController - MapViewController, with an
xib onto which I put an MKMapView in IB.
3) Have MapViewController implement MKMapViewDelegate and set the the
controller as the delegate of the map view.
4) Implement the delegate method mapViewDidFinishLoadingMap as follows
(no idea if this is the 'right' way!):
for each photo
create PhotoAnnotation
add annotation to mapView
retrieve annotationView for annotation from mapView
create disclosure button
set disclosure button as rightCalloutAccessoryView of
annotationView
release annotation
5) Implement the delegate method calloutAccessoryControlTapped as
follows:
get photo from photoAnnotation
create and push PhotoDetailViewController exactly as from
PhotoListViewController
I don't know why they suggested looking at UINavigationController to
work out how to do the last step as if your view controller is the map
delegate you can call self.navigationController. Again, perhaps I was
missing something?
Vicki
I've just started the map portion of the assignment, but I'm having
trouble retrieving the data from the database from my
MapViewController. I've loaded all the geo-tagged photos from Flickr
into my PersonListViewController and all the information is displaying
correctly. When I switch over to the MapViewController and call a
method in the PersonListViewController to fetch the data, it crashes
here:
[NSEntityDescription entityForName:@"Person"
inManagedObjectContext:moc]
with the error:
*** Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: '+entityForName: could not
locate an NSManagedObjectModel for entity name 'Person''
I just tried copying and pasting the code to fetch the data from the
PersonListViewController to the MapViewController, which doesn't crash
the application, but the fetch returns nil. From the debugger, the
moc appears to be the same in both view controllers, as it should be
since I'm accessing it from the singleton. Is there something I'm
missing to be able to access the database I've set up in the
PersonListViewController from my MapViewController.
Thanks,
Lenny
Vicki - "walk in the park"... until you get to the annotation part. I
purposely didn't read your walkthrough so that I could try it on my
own first. In the end, I basically did the same thing you did with
these minor differences:
1. I implemented the annotations in the viewWillAppear method instead
of mapViewDidFinishLoadingMap. I think yours make more sense.
2. I couldn't tell from your walkthrough where you created the
disclosure button. It looks like you did it in
mapViewDidFinishLoadingMap. I created mine in the
mapView:viewForAnnotation delegate, which was simple to do.
For me, I thought the hardest part was trying to figure out how to
pass the image binary to reuse PhotoDetailViewController when the
disclosure button was clicked.
Yeah, that annotation part was tricky! Documentation there seems
rather lacking to me....
I'd love to know how you added the disclosure button in
viewForAnnotation. I tried to do it in there but I couldn't get it to
work. I tried calling [mapView viewForAnnotation] in there and got
nil, not unsurprisingly, which is why I did it in the other method. I
also tried creating my own MKPinAnnotationView and got a pin on the
map but nothing happened when I clicked on it, so I was clearly
missing something. Send me a direct reply if you don't want to post
the code.
I found the disclosure button part fairly straightforward, as I
noticed that funny callback method on the delegate in the lecture
notes. It would never have occurred to me to look there though!
Vicki