下面的代码是我到目前为止使用的代码,它正确地循环遍历数组中的每个对象,但是当我尝试将它们全部显示在一个地图上时,它只将数组中的最后一个obeject添加到地图中,不是所有20个左右我想要显示。
self.clientTable = [ClientDatabase database].clientTable;
ClientTable *info = nil;
[_nameLabel setText:info.name];
[_stateLabel setText:info.state];
//change the string to doubles for the map GPS co-ordinates
double latDouble = [info.latMap doubleValue];
double longDouble = [info.longMap doubleValue];
NSLog(@"%d",[self.clientTable count]);
int countArray = [self.clientTable count];
for (int i=0;i<countArray;i++) {
info = [self.clientTable objectAtIndex:i];
info.uniqueId=i;
NSLog(@" i = %d ; id = %d %@",i, info.uniqueId, info.name);
//set up the map
[super viewDidLoad];
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
MKCoordinateRegion region = {{0.0,0.0},{0.0,0.0}};
region.center.latitude = latDouble;
region.center.longitude = longDouble;
region.span.longitudeDelta =0.02; //degrees of acuracy, most precise best for this time
region.span.latitudeDelta =0.02; //degrees of accuracy
[mapView setRegion:region animated:YES];
// set up the annotation point
AllMap *annotationPoint = [[AllMap alloc] init];
annotationPoint.title = info.name;
annotationPoint.subtitle = info.state;
annotationPoint.coordinate = region.center;
[mapView addAnnotation:annotationPoint];
annotationPoint.isAccessibilityElement=YES;
//show annotation by default
[mapView selectAnnotation:annotationPoint animated:YES];
[mapView setDelegate:self];
}
对不起,如果代码是垃圾,我是iPhone编程的新手。
提前致谢:D
答案 0 :(得分:1)
看起来你正在[super viewDidLoad]
循环中调用for
,这可能会重置mapView的注释数组。此方法只应调用一次,因此如果您在for
语句之前移动它,则可能会获得更好的结果。
答案 1 :(得分:0)
为什么要在创建注释的循环内部设置地图?
这是一篇旧的博客文章,但它涵盖了基础知识,应该让你回到正轨