删除现有注释并将新注释添加到mapview中

Xav*_*ero 6 iphone mkmapview ios

我正在加载一个带有单个注释的mapview.就像iphone中的"地图应用"一样.我有一个搜索栏,显示引脚位置的地址,如地图所示.现在我决定更改位置地址.我在搜索栏中输入新的地址位置.然后我的mapview必须删除现有的注释并添加新的注释.现在,我正在添加新注释,但我无法删除现有注释.如何删除现有注释?

Abi*_*ern 8

首先,在地图视图上获取注释列表,然后删除不是当前用户位置的注释(即在MKUserLocation类中).

NSArray *annotations = [mapView annotations];
for (id annotation in annotations) {
    if (annotation isKindOfClass:[MKUserLocation class]) {
        continue;
    }
    [mapView removeAnnotation:annotation];
}
Run Code Online (Sandbox Code Playgroud)

然后您可以正常添加新注释.