2013-04-22 57 views
1

我想將自定義註釋傳遞給NSMutableArra以便使用它來填充表視圖。 的代碼是:iphone將註釋傳遞給數組

在.H我限定NSMutableArray *mapViewAnnotations;

然後在.M

- (void)plotBarPosition:(NSString *)datos{ 

/* 
code that extract data froma a json string 
*/ 
    MyLocation *nota =[[MyLocation alloc] initWithName:barNamePlusDistance coordinate:coordinate horario:horario oferta:offerta more:info];   
       NSLog(@"nota :%@",nota); 

      [_mapView addAnnotation:nota]; //annotation are plot on the map 

      [mapViewAnnotations addObject:nota]; 

      NSLog(@"mapViewAnnotations:%@",mapViewAnnotations); //NSlog return null 
    } 

mapViewAnnotations導致空。 Perarps無法將MyLocation對象複製到可變陣列中?

在此先感謝。

+1

似乎你從來沒有初始化你的NSMutableArray.It默認情況下有一個空值。 – FreeNickname 2013-04-22 18:56:35

+0

http://stackoverflow.com/questions/6410798/annotation-on-the-map-problem/6411217#6411217 – rptwsthi 2013-04-22 18:58:05

回答

1

在viewDidLoad或其他方法中初始化這個數組來初始化數組。

_mapViewAnnotations = [NSMutableArray array]; 
+0

你說得對。現在我得到這樣的東西:(「」,「」,「」 )我可以用它來填充表嗎? – doxsi 2013-04-22 19:13:12

+1

正確,現在可以使用MyLocation * nota = [_mapViewAnnotations objectAtIndex:0]訪問數組中的對象; //或者適當的索引。 – 2013-04-22 19:15:47

+0

非常感謝!現在很清楚 – doxsi 2013-04-22 19:37:36