私は、ユーザーがピンを選択するとそのピンの詳細画面に行くピンを持つマップビューを持っています。また、ユーザーがアイテムを選択すると、同じタイプの詳細ビューに移動するテーブルビューがあります。ここでiOS 4.2のマップアノテーションとMKMapViewの問題?
が問題だ...
3.1.3から4.1に至るまでには正常に動作するようです。ピンと一致する詳細ビューです。しかし、私はiOS 4.2にアップグレードしたばかりのユーザーしかいないし、4.1の下では正常に機能していると言いますが、4.2ではピンの選択によって別のピンの詳細が表示されます。しかし、テーブルビューではまだうまく動作します。
iOS 4.2のMKMapViewで、pinIDの選択方法が変更された可能性はありますか?
追加 - 私はviewForAnnotationの関連する部分を追加し、checkButtonTappedいる
- (MKPinAnnotationView *)mapView:(MKMapView *)eMapView viewForAnnotation:(id <MKAnnotation>)annotation {
int postTag = 0;
MKPinAnnotationView *pinView = (MKPinAnnotationView *)[eMapView dequeueReusableAnnotationViewWithIdentifier:@"Pin"];
if(pinView == nil) {
pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"];
pinView.frame = CGRectMake(0, 0, 25, 25);
} else {
pinView.annotation = annotation;
}
// Set up the Right callout
UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
myDetailButton.frame = CGRectMake(0, 0, 23, 23);
myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[myDetailButton addTarget:self action:@selector(checkButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
// Identify which pin is being selected
if ([[annotation title] isEqualToString:@"Current Location"]) {
postTag = 99999;
} else {
postTag = [annotation getPinID];
}
myDetailButton.tag = postTag;
pinView.rightCalloutAccessoryView = myDetailButton;
pinView.animatesDrop = YES;
// Set to show a callout on the pin
pinView.canShowCallout = YES;
return pinView;
}
// Method to show detail view when the callOut button is selected
- (IBAction) checkButtonTapped: (id) sender {
int nrButtonPressed = ((UIButton *)sender).tag;
if (nrButtonPressed < 99999) {
if (self.showDetailView == nil) {
DetailData *tmpViewController = [[DetailData alloc] initWithNibName:@"Detail" bundle:nil];
self.showDetailView = tmpViewController;
[tmpViewController release];
}
buttonDetail = [[mapView annotations] objectAtIndex:(nrButtonPressed-1)];
NSMutableArray *tmpArray = [NSMutableArray arrayWithObjects: [buttonDetail getDataI], [buttonDetail getDataII], [buttonDetail getDataIII], [buttonDetail getDataIV], [buttonDetail getDataV], nil];
self.showDetailView.eventData = [[NSMutableArray alloc] initWithArray:tmpArray copyItems:YES];
[self.navigationController pushViewController:self.showDetailView animated:YES];
[self.showDetailView.eventData release];
}
}
あなたが見ることができるように、checkButtonTappedに私はそのピンに対する注釈からデータを収集し、選択したピンを記録。問題は、nrButtonPressedが間違っているようです。しかし、コンパイル時には問題ありません。
ピン選択を処理するviewForAnnotationメソッドとコードを表示します。 – Anna
コードを投稿するのはうれしいでしょうが(ちょっと長いですが)、それは問題ではないと思います。その理由は、私が4.1でコンパイルしたバージョンをiPod touchとその上で実行しているからです。私はviewForAnnotationを変更せず、4.2でコンパイルしたときにシミュレータ(iPhone 4.2をエミュレートする)にエラーがあります。ユーザーは古いバージョンのアプリケーションが4.1でうまくいきましたが、4.2に同じバージョンエラーの表示を開始しました。もしあなたがそうしたら私はそれを掲示するので、あなたはまだコードを望んでいますか? – LancDec
コードが非常に長くて複雑な場合は、デバッグを行い、トラブル領域を特定する必要があります。別の小さなプロジェクトで問題を再現してみてください。 Appleの[リリースノート](https://developer.apple.com/library/ios/#releasenotes/General/RN-iOSSDK-4_2/index.html)に記載されている4.2 MapKitの唯一の違いは、 (Notesと既知の問題のMapKitエントリを参照してください)。これはあなたに関連するかもしれません。 – Anna