我有一個新的問題,我不知道爲什麼...我的進一步的解決方案是由羅布張貼here。我喜歡他的工作,它的工作非常好,直到更新到iOS 6.1。MKCoordinateRegionMakeWithDistance引發「線程1:信號SIGABRT」
- (void)loadKml:(NSURL *)url
{
// parse the kml
Parser *parser = [[Parser alloc] initWithContentsOfURL:url];
parser.rowElementName = @"Placemark";
parser.elementNames = @[@"name", @"Snippet", @"coordinates", @"description"];
parser.attributeNames = @[@"img src="];
[parser parse];
// add annotations for each of the entries
for (NSDictionary *locationDetails in parser.items)
{
MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
annotation.title = locationDetails[@"name"];
annotation.subtitle = locationDetails[@"Snippet"];
NSArray *coordinates = [locationDetails[@"coordinates"] componentsSeparatedByString:@","];
annotation.coordinate = CLLocationCoordinate2DMake([coordinates[1] floatValue], [coordinates[0] floatValue]);
[self.mapView addAnnotation:annotation];
}
// update the map to focus on the region that encompasses all of your annotations
MKCoordinateRegion region;
if ([self.mapView.annotations count] > 1)
{
region = [self regionForAnnotations:self.mapView.annotations];
region = MKCoordinateRegionMake(region.center, MKCoordinateSpanMake(region.span.latitudeDelta * 1.05, region.span.longitudeDelta * 1.05)); // expand the region by 5%
}
else
{
id<MKAnnotation> annotation = self.mapView.annotations[0];
region = MKCoordinateRegionMakeWithDistance(annotation.coordinate, 100.0, 100.0); // >>>this line throws: "Thread 1: signal SIGABRT"<<<
}
[self.mapView setRegion:region animated:YES];
}
自iOS 6.1模擬器升級以來,它不工作。
編輯:我得到這個錯誤:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
1)是鉤2.)我不知道我怎麼能測試它3.)我嘗試了代碼,我的應用程序將運行沒有錯誤,但與空地圖4.)更正:-) – CTSchmidt 2013-03-20 10:33:47
@CurtisTimoSchmidt 2.將NSLog語句放在提供例外的行之前。或者更好的是,通過該代碼放置一個斷點並單步執行。 (請參閱[WWDC 2012調試視頻](https://developer.apple.com/videos/wwdc/2012/?id=415)或參閱[Xcode用戶指南](https://developer.apple.com/library/) ios/documentation/ToolsLanguages/Conceptual/Xcode_User_Guide/060-Debug_and_Tune_Your_App/debug_app.html#// apple_ref/doc/uid/TP40010215-CH3-SW38)。)當你得到這樣的異常時,它總是因爲一些無效的變量正在傳遞給某些方法/功能。 – Rob 2013-03-20 12:45:17
我已經標註了註釋的代碼行,請參閱:'region = MKCoordinateRegionMakeWithDistance(annotation.coordinate,100.0,100.0);'如果我這樣做'NSLog(@「%@」,annotation.coordinate);'befor and after這行我會得到一個警告:'格式指定類型「ID」,但參數的類型CCLocationCoordinate2D'我有點困惑 – CTSchmidt 2013-03-20 13:28:13