May 16, 2010
Revisited – Custom callout bubble in MKMapView, final solution!
I thought I had the final solution for custom callout bubbles in MKMapView but I was wrong. There were a couple of errors found after testing.
- If you press and hold it moves focus to the real callout bubble offset 10000px right and 10000px down
- It did not work on the iPad (iPhoneOS 3.2) and iPhoneOS 4.0
- There is a leak on the property observer
My latest solution solves the first two but not the third one. It works with iPhoneOS 3.0, 3.1, 3.2 and 4.0. I have only tested in simulator for 3.2 and 4.0.
To make it a easier to look at the code I have created my first github repository. You can alsoe download source for master (zip or tar) directly from github.
Update: I got my application, Gasmacken approved (2010-05-23) with this solution.
[...] Custom callout bubble in MKMapView, final solution! Once again, this post has been updated. [...]
Hello, Jakeri. Thanks for your work.
I’ve used your final solution which is not revised one. So I faced same problems as you mentioned on this post. After I downloaded your revised solution, I tried to find differences with last version and fix some part of code in my project but it didn’t work on iPhone 4.0. The problem I got is first one, callout bubble. Could you let me know which part of code you revised for solving the problem related with callout bubble? Thanks a lot!
Sorry, I found it. Thanks.
Hello Jakeri,
Does “leak on the property observer” you are talking about does concern the fact that you never remove the observer from the annotations view ? If so, maybe this solution would fit:
When you create MyAnnotationView objects, add them to to a NSMutableArray list. Then, in dealloc, do:
for (annotations id in list)
[annotation removeObserver:self forKeyPath:@"selected"];
Do you think this would solve the problem ?
By the way, I have a question: where have you gathered the information to write this line:
[UIView beginAnimations: @"moveCNGCallout" context: nil];
in particular, the “moveCNGCallout” thing ?
Thanks a lot, your tutorial is helpful
Waouw, sorry, I have sent to quickly my comment. Some little mistakes :
for (id annotation in list) //instead of “annotation id”
[annotation removeObserver:self forKeyPath:@"selected"];
Hi,
I tried some stuff with dealloc and the warning but I found out something that I can not remember right now. I believe that it had todo something with the order of dealloc and calling removeObserver.
If you find a solution please clone my github repo and I will merge it into master.