2011-03-25 45 views
0

我需要後,每次20秒我怎麼能做到這一點MapView的註解視圖

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

} 
+0

您可以提供一些代碼來初始化您的註釋嗎? – 2011-03-25 13:26:48

+0

for(int i = 0; i <[_shadowArray count]; i ++) \t { \t \t Shadows * shadowObj1; \t \t \t shadowObj1 = [_shadowArray objectAtIndex:i]; \t \t CLLocationCoordinate2D location1; \t \t \t \t location1.latitude = [shadowObj1.position_x floatValue]; \t location1.longitude = [shadowObj1.position_y floatValue]; \t \t \t \t \t annotaionObj = [[AnnotationDelegate頁頭] initWithCoordinate:LOCATION1名:@ 「」 子:@ 「!趕上我」]; \t \t [_annotationArray addObject:annotaionObj]; \t \t [_mapView addAnnotation:annotaionObj]; \t \t \t } – 2011-03-25 13:27:33

+0

可以我改變註釋的VIW當用戶位置變化 – 2011-03-25 13:36:46

回答

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 PLZ的更多信息,請閱讀以下SO帖子。

How do I use NSTimer?

+0

@Manish Jain:你還有沒有討論過的問題...... – Jhaliya 2011-03-26 06:39:44