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
、マップ上ではメモリ内の最後のテーブルのもののみが呼び出されます。以前と同じ結果を得るために set i delegate メソッドをどこで取得できますか? ViewForAnnotation
iPad 6.0 シミュレーターでは正常に動作しますが、iPad シミュレーター 5.1 では動作せず、コードは同じです