mkplaceMark에서 setcoordinate 호출 '인식 할 수없는 선택기'를 사용하여 앱을 충돌합니다.

StackOverflow https://stackoverflow.com//questions/9647486

문제

MKMAPVIEW가 단일 MKPLACEMARK를 추가하여 사용자가 방금 선택한 건물의 위치를 나타냅니다.사용자는 한 번에 하나의 건물을 하나만 선택할 수 있으며 새 건물을 선택할 때 플레이스 마크를 새 건물로 이동시키고 싶습니다.첫 번째 빌드에서 선택하면 잘 작동하며지도에 PIN을 놓습니다.새로운 건물을 선택할 때 마커의 위치를 업데이트하기 위해 PlaceMark에서 setCoordinate를 시도하고 Call TrankeReMark로 전화를 걸 때 -[MKPlacemark setCoordinate:]: unrecognized selector sent to instance 을 얻습니다.

MyViewController.h의 경우 :

@property (nonatomic, strong)MKPlacemark *selectedBuildingPlacemark;
.

myViewController.m

@synthesize selectedBuildingPlacemark;

...

if (self.selectedBuildingPlacemark == nil) {
        self.selectedBuildingPlacemark = [[MKPlacemark alloc] initWithCoordinate:myCoord addressDictionary:nil];
        [mapView addAnnotation:self.selectedBuildingPlacemark];
    }
    else {
        [self.selectedBuildingPlacemark setCoordinate:myCoord];
    }
.

나는 mkplaceMark가 mkannotation에 부합되었고 따라서 setCoordinate를 구현해야한다고 생각했다.누군가가 내 방식의 오류를 보여줄 수 있습니까?

도움이 되었습니까?

해결책

The documentation of MKAnnotation says:

Annotations that support dragging should implement this method to update the position of the annotation.

So the method setCoordinate: is optional and is only implemented by classes that support dragging. The documentation of MKPlacemark does not reference that method, so it is not implemented.

So you should create a new instance every time you select a new building.

다른 팁

If you don't specifically need to use an MKPlacemark (it doesn't look like it because you're passing nil for the addressDictionary), you could use the MKPointAnnotation class instead.

MKPointAnnotation implements MKAnnotation but adds a setCoordinate method.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top