2010-04-17 3 views

Répondre

4

Vous pouvez mettre en œuvre cette méthode comme ceci:

-(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated 
{ 
    NSNumber *animatedNumber = [NSNumber numberWithBool:animated]; 
    NSArray *args = [[NSArray alloc] initWithObjects:mapView, 
                animatedNumber,nil]; 

    [self performSelector:@selector(delayedMapViewRegionDidChangeAnimated:) 
      withObject:args 
      afterDelay:2.0f]; 

    [args release]; 
} 

Puis, quelque part dans la même classe:

-(void)delayedMapViewRegionDidChangeAnimated:(NSArray *)args 
{ 
    MKMapView *mapView = [args objectAtIndex:0]; 
    BOOL animated = [[args objectAtIndex:1] boolValue]; 

    // do what you would have done in mapView:regionDidChangeAnimated: here 
} 

Bien sûr, si vous n'avez pas besoin l'un de ces arguments (soit mapView ou animated), vous pourriez rendre cela considérablement plus simple en passant seulement celui dont vous aviez besoin.

Si vous ne pouvez pas modifier le code de votre MKMapViewDelegate, vous pourriez peut-être faire quelque chose de similaire avec la méthode swizzling, bien que vous obtenez vraiment aki.

+0

remercie l'homme pour l'aide – Nanz

0

Vous pouvez envoyer un message différé avec performSelector:withObject:afterDelay: ou l'une de ses méthodes associées.

Questions connexes