MapView注释视图

时间:2011-03-25 13:24:00

标签: iphone

我需要在每20秒后更改注释视图我该怎么做

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];

}

1 个答案:

答案 0 :(得分:0)

您可以使用计时器,每20秒后重复一次..

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

如果您不再需要计时器,首先需要使其无效,然后分配一个零值

[m_Timer invalidate];
 m_Timer = nil; 

因此,您的文件应该包含所有这些内容。

   -(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];

   }

}

要了解更多有关NSTimer的信息,请阅读以下SO帖子。

How do I use NSTimer?