Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

inverted

macrumors newbie
Original poster
Jul 3, 2009
4
0
hey

i am using an MKMapView. i initialize it directly from the code.
when i touch an annotation on the map i 'move' (transfer) another view above the MKMapView to show to the user some details about the annotation.

now my question, how do i handle a touch somewhere else on the map ? cause in this case i want to close the details view again.

thank you for your help !
 
Apple Developer Support Dude said:
Hi Jeremy,

All you need to do is subclass MKMapView and override selectAnnotation:animated: as follows:

@implementation MyMapView

- (void)selectAnnotation:(id <MKAnnotation>)annotation animated:(BOOL)animated {
[super selectAnnotation:annotation animated:animated];
NSLog(@"%s", __FUNCTION__);
// do whatever you want with the annotation here...
}

@end

Wil Turner
Apple Developer Technical Support
UIKit • Core Data • Performance

That will tell you when an annotation is selected. Too bad I couldn't even get the sample code to work :confused:. If you get it to work please post your code.
 
hi, i was able to handle the "select"-event. for that i made my own subclass from "MKAnnotationView" and overwrote the - (void)setSelected:(BOOL)selected animated:(BOOL)animated; method.
but the way you showed me is much better. you don't mess up with the responsibility.

but i am looking for a solution to do the opposite :) i have to handle a touch inside the map, and not on an annotation.
i need that to hide my detailsView.

thanks
 
haha sometimes i could kick myself !
i found the answer :

@interface FriendAnnotationView : MKAnnotationView {
....

- (void)setSelected: (BOOL)selected animated: (BOOL)animated{

if(selected){
[self.delegate showDetailsToFriend];
}
else{
[self.delegate hideDetailsToFriend];
}

[super setSelected:selected animated:animated];
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.