我开始使用 iOS6 构建一个运行良好的应用程序,但后来由于更强大的原因,我不得不切换到 IOS5。但是,有一张地图一直给我带来问题。这张地图有许多类型的annotationView(例如电影院、餐馆、剧院......),每个都有自己的图像。当我从 iOS6 传递到 iOS5 时,我注意到 annotationView 的行为与以前不同,因为构造它们的委托方法的调用不再相同。我能做些什么?
-(void)viewDidLoad{
//.....
//extraction of elements from the tables in a database
for(int i=0; i<7; i++){ //extraction tables from database
//......
for (int i =0; i< number; i++) { //extraction elements from tables
self.chinaTable =[self.mutableArray objectAtIndex:i];
CLLocationCoordinate2D coord=CLLocationCoordinate2DMake(self.chinaTable.latitudine, self.chinaTable.longitudine);
AnnotationCustom *annotationIcone =[[AnnotationCustom alloc]initWithCoordinates:coord title:self.chinaTable.titolo subTitle:self.chinaTable.indirizzo];
//.......
[self.mapView addAnnotation:annotation];
self.locationManager.delegate = self;
self.mapView.delegate=self; //the problem is here
}
}
委托方法
- (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id
<MKAnnotation>)annotation
{
NSLog (@"the name of the table is %@", self.nomeTabella);
// this NSLog you get only the name of the last open table
//..........
if ([annotation isKindOfClass:[AnnotationCustom class]]){
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKAnnotationView *annotationView = (MKAnnotationView*) [mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
annotationView = [[MKAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];
annotationView.annotation = annotation;
AnnotationCustom *customAnnotation = (AnnotationCustom *)annotationView.annotation;
//I create an annotation different depending on the name of the table of provenance
if ([self.nomeTabella isEqualToString:@"Cinema"]){
if(UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPhone){
annotationView.image = [UIImage imageNamed:@"iphone_cinema.png"];
customAnnotation.nomeTabella = self.nomeTabella;
customAnnotation.ID = self.chinaTable.ID;
customAnnotation.china = self.chinaTable;
}else{
annotationView.image = [UIImage imageNamed:@"ipad_cinema.png"];
customAnnotation.nomeTabella = self.nomeTabella;
customAnnotation.ID = self.chinaTable.ID;
customAnnotation.china=self.chinaTable;
}
//......
}
委托方法viewForAnnotation
不再在每个注解构建后被调用,而是仅在两个循环结束时调用,因此annotationView
映射上只有内存中最后一个表的那些。我在哪里可以设置我委托方法以获得与以前相同的结果?ViewForAnnotation
在 iPad 6.0 模拟器中工作正常,但在 iPad 模拟器 5.1 中不起作用,代码相同