You need to pass your view.annotation as userInfo object and implement hideMKAnnotation as
- (void)hideMKAnnotation:(NSTimer*)timer
{
id aview = timer.userInfo;
[self.mapView deselectAnnotation:aview animated:YES];
}
質問
I have a problem hiding a MKAnnotationView
after some time [4 seconds]. I have a MKMapView
named mapView which shows user location with MKUserLocation
and I have added a UIButtonTypeDetailDisclosure
to his MKAnnotationView
. The MKAnnotationView
automatically gets selected but I want to deselect it after some time with a NSTimer
. I have correctly implemented the timer and the void method gets called correctly [I have checked it with a NSLog
] but I don't know what code to write in the void method to make the annotation disappear.
this is my code:
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
for (MKAnnotationView* view in views)
{
if ([view.annotation isKindOfClass:[MKUserLocation class]])
{
view.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[self.mapView selectAnnotation:view.annotation animated:YES];
}
mKAnnotationHideTimer = [NSTimer scheduledTimerWithTimeInterval:4.0
target:self
selector:@selector(hideMKAnnotation:)
userInfo:nil
repeats:NO];
}
}
- (void)hideMKAnnotation:(NSArray *)views
{
// What code here?
}
Can someone help me writing the code?
解決
You need to pass your view.annotation as userInfo object and implement hideMKAnnotation as
- (void)hideMKAnnotation:(NSTimer*)timer
{
id aview = timer.userInfo;
[self.mapView deselectAnnotation:aview animated:YES];
}