なぜ私のコードはマップアノテーションを削除しないのですか?ボタンをクリックしてアノテーションを削除ボタン(作成したアノテーション)
私はボタンを押して、ユーザーの場所を取得し、マップに固定します。問題は、ボタンが2番目、3番目、.......の時間に当たったときです。最初のピンを削除する代わりにピンを追加し続けるだけです(ピンの置換をシミュレート)。
私は別のボタン(クリアピン)を追加してこのスレッドに続いてみました:http://stackoverflow.com/questions/3027392/how-to-delete-all-annotations-on-a-mkmapviewデバッグ情報なしでクラッシュします。
しかし、理論的には私のコードはうまくいくはずです。では、私は何を理解していないのですか?
- (IBAction)getLocation:(id)sender {
MapAnnotation *ann1 =[[[MapAnnotation alloc] init]autorelease];
// remove annotation
[mapView removeAnnotation:ann1];
locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter=kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[locationManager startUpdatingLocation];
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
MKCoordinateRegion region = {{0.0,0.0},{0.0,0.0}};
region.center.latitude = locationManager.location.coordinate.latitude;
region.center.longitude = locationManager.location.coordinate.longitude;
region.span.longitudeDelta = 0.005f;
region.span.latitudeDelta = 0.005f;
[mapView setRegion:region animated:YES];
[mapView setDelegate:sender];
MKCoordinateRegion location1;
location1.center.latitude =locationManager.location.coordinate.latitude;
location1.center.longitude= locationManager.location.coordinate.longitude;
location1.span.longitudeDelta=0.1;
location1.span.latitudeDelta =0.1;
// Add Annotation
//MapAnnotation *ann1 =[[MapAnnotation alloc] init];
[email protected]"You Parked Here";
[email protected]"";
ann1.coordinate= location1.center;
[mapView addAnnotation:ann1];
}
ありがとうございました。 } [:注釈のMapView removeAnnotation]; { 続行: (注釈のIDアノテーション) { IF([MKUserLocationクラス]アノテーションisKindOfClass])のための、Iは[のMapView注釈]「にNSArray *注釈=をしようとしていました; } "しかし、それはクラッシュし続けました。これは素晴らしいです – Rick
あなたはそれを使用している間、配列を変更したくない可能性があります。 – joshpaul
データベースからピンレコードを削除したい場合、このロジックを使用して正しいピンからピンを削除できますか?ピンをクリックすると、pin_idですべてのレコードが取得されていますが、クリックされたピンのピンIDは見つかりませんでしたか?あなたはこの状況から出てくるのを助けてくれますか? –