0

i need to change the view of annotation after each 20 second how can i do it

for (int i = 0; i < [_shadowArray count]; i++)
{
    Shadows* shadowObj1;

    shadowObj1 = [_shadowArray objectAtIndex:i];
    CLLocationCoordinate2D location1;   

    location1.latitude =  [shadowObj1.position_x floatValue];
    location1.longitude = [shadowObj1.position_y floatValue];   

    annotaionObj = [[AnnotationDelegate alloc] initWithCoordinate:location1 name:@"" sub:@"Catch me! "];
    [_annotationArray addObject:annotaionObj];
    [_mapView     addAnnotation:annotaionObj];

}
Manish Jain
  • 865
  • 3
  • 13
  • 28
  • Can you provide some code how you initialize your annotations? – Nick Weaver Mar 25 '11 at 13:26
  • for (int i = 0; i < [_shadowArray count]; i++) { Shadows* shadowObj1; shadowObj1 = [_shadowArray objectAtIndex:i]; CLLocationCoordinate2D location1; location1.latitude = [shadowObj1.position_x floatValue]; location1.longitude = [shadowObj1.position_y floatValue]; annotaionObj = [[AnnotationDelegate alloc] initWithCoordinate:location1 name:@"" sub:@"Catch me! "]; [_annotationArray addObject:annotaionObj]; [_mapView addAnnotation:annotaionObj]; } – Manish Jain Mar 25 '11 at 13:27
  • can i change the viw of annotation when user location change – Manish Jain Mar 25 '11 at 13:36
  • Do'nt use NSTask from documentation ---- An NSTask object can only be run once. Subsequent attempts to run the task raise an error. – Jhaliya - Praveen Sharma Mar 25 '11 at 13:37
  • sorry, NSTimer, not NSTask, should my answer be – Marek Sebera Mar 25 '11 at 13:44

1 Answers1

0

You could use the timer,which will repeat after each 20 second ..

NSTimer* m_Timer;
m_Timer =  [NSTimer scheduledTimerWithTimeInterval:2.0
        target:self
        selector:@selector(MyMethod)
        userInfo:nil
        repeats:YES];

if you don't require timer any more ,you first need to invalidate it then assign a nil value

[m_Timer invalidate];
 m_Timer = nil; 

So your file should all these things like.

   -(void) MyMethod
    {
      [self viewAnotation];
    }

-(void) viewAnotation
{

   for (int i = 0; i < [_shadowArray count]; i++)
   {
    Shadows* shadowObj1;

    shadowObj1 = [_shadowArray objectAtIndex:i];
    CLLocationCoordinate2D location1;   

    location1.latitude =  [shadowObj1.position_x floatValue];
    location1.longitude = [shadowObj1.position_y floatValue];   

    annotaionObj = [[AnnotationDelegate alloc] initWithCoordinate:location1 name:@"" sub:@"Catch me! "];
    [_annotationArray addObject:annotaionObj];
    [_mapView     addAnnotation:annotaionObj];

   }

}

To know more for NSTimer plz read the below SO post.

How do I use NSTimer?

Community
  • 1
  • 1
Jhaliya - Praveen Sharma
  • 31,697
  • 9
  • 72
  • 76