Iphone 从mapview中移除pin时崩溃
我正在使用MapView,它有两个按钮。 1) 中心按钮: 此按钮将pin注释放置在当前地图的中心。 按下此按钮时,我将最后一个注释存储在NSMutable数组中。 然后从mapview中删除最后一个注释,并在地图中心放置一个销 我为这部分所做的代码如下: 落针功能Iphone 从mapview中移除pin时崩溃,iphone,objective-c,ios5,Iphone,Objective C,Ios5,我正在使用MapView,它有两个按钮。 1) 中心按钮: 此按钮将pin注释放置在当前地图的中心。 按下此按钮时,我将最后一个注释存储在NSMutable数组中。 然后从mapview中删除最后一个注释,并在地图中心放置一个销 我为这部分所做的代码如下: 落针功能 - (void)PinDropwithlatitude:(double)lat longitude:(double)longi droptitle:(NSString *)title { CLLocationCoordina
- (void)PinDropwithlatitude:(double)lat longitude:(double)longi droptitle:(NSString *)title
{
CLLocationCoordinate2D theCoordinate;
theCoordinate.latitude = lat;
theCoordinate.longitude = longi;
MKCoordinateRegion region;
region.center.latitude = theCoordinate.latitude;
region.center.longitude = theCoordinate.longitude;
//Set Zoom level using Span
MKCoordinateSpan span;
span.latitudeDelta =0.005;
span.longitudeDelta =0.005;
region.span = span;
[MapView setRegion:region animated:YES];
SetLat =lat;
SetLong =longi;
DDAnnotation *annotation = [[[DDAnnotation alloc] initWithCoordinate:theCoordinate addressDictionary:nil] autorelease];
annotation.title = title;
annotation.subtitle = [NSString stringWithFormat:@"%f %f", annotation.coordinate.latitude, annotation.coordinate.longitude];
[MapView addAnnotation:annotation];
}
当我按下中间按钮时,我正在执行以下代码并将最后一个数组存储在注释中
-(IBAction)CenterPressed:(id)sender
{
//40.439631,-3.698273 -spain centre
[lastAnnotation addObjectsFromArray:MapView.annotations];
NSLog(@"last annotation array=%@",lastAnnotation);
for (id annotation in [MapView annotations])
{
if ([annotation isKindOfClass:[MKUserLocation class]])
{
continue;
}
[MapView removeAnnotation:annotation];
}
[self PinDropwithlatitude:SetLat longitude:SetLong
droptitle:NSLocalizedString(@"Title", nil)];
}
阵列的日志显示了
您可以在下面看到的最后注释::
last annotation array=(
"<+40.43963100,-3.69827300> +/- 0.00m",
"<+40.43923187,-3.68722200> +/- 0.00m",
"<+40.43792343,-3.67670774> +/- 0.00m",
"<+40.43772888,-3.66711617> +/- 0.00m"
)
但是当我按下撤消按钮时,它会崩溃,并出现以下错误
-[DDAnnotation annotation]:无法识别的选择器发送到实例0x79b8f40
我不知道问题到底出在哪里。有谁能帮我指出上面代码中的错误吗
谢谢你能试试吗
[lastAnnotation lastObject]
而不是
[[lastAnnotation objectAtIndex:[lastAnnotation count]-1]
像
你能试试吗
[lastAnnotation lastObject]
而不是
[[lastAnnotation objectAtIndex:[lastAnnotation count]-1]
像
谢谢你的建议,我已经试过了,但问题仍然存在。我认为缺少某些内容。如果[lastAnnotation count]==1,则删除一个批注,然后[[lastAnnotation objectAtIndex:[lastAnnotation count]-1]批注]可能会获得一个randon值unsafeyou必须确保lastAnnotation不为空我在按下undobuttonif([lastAnnotation count]>0)时正在检查然后,只有它允许您从地图中删除注释谢谢您的建议,我已经尝试过了,但问题仍然存在。我认为缺少某些内容。如果[lastAnnotation count]==1,则删除一个批注,然后[[lastAnnotation objectAtIndex:[lastAnnotation count]-1]批注]可能会获得一个randon值unsafeyou必须确保lastAnnotation不为空我在按下undobuttonif([lastAnnotation count]>0)时正在检查然后,只有它允许您从地图中删除注释