4秒后,我在隐藏一个MKAnnotationView时遇到了问题。我有一个名为MKMapView的mapView,它用MKUserLocation显示用户的位置,并在MKAnnotationView中添加了UIButtonTypeDetailDisclosure。MKAnnotationView会自动被选中,但我希望在使用NSTimer之后取消选择它。我已经正确地实现了计时器,并正确地调用了void方法,我用一个NSLog检查了它,但是我不知道在void方法中编写什么代码来使注释消失。
这是我的密码:
- (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?
}有人能帮我写代码吗?
发布于 2014-01-26 12:16:55
您需要将view.annotation作为userInfo对象传递,并将hideMKAnnotation实现为
- (void)hideMKAnnotation:(NSTimer*)timer
{
id aview = timer.userInfo;
[self.mapView deselectAnnotation:aview animated:YES];
}https://stackoverflow.com/questions/21363114
复制相似问题