im试图在地图上同时显示两个json文件。但有一个问题,它给了我一些奇怪的错误,我无法弄清楚。所以最初有
- (void)viewDidLoad {
[super viewDidLoad];
NSMutableArray * annotations = [[NSMutableArray alloc] init];
self.mapView.visibleMapRect = MKMapRectMake(135888858.533591, 92250098.902419, 190858.927912, 145995.678292);
NSLog(@"Loading data…");
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSData * JSONData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:self.seedFileName ofType:@"json"]];
for (NSDictionary * annotationDictionary in [NSJSONSerialization JSONObjectWithData:JSONData options:kNilOptions error:NULL])
{
ADClusterableAnnotation * annotation = [[ADClusterableAnnotation alloc] initWithDictionary:annotationDictionary];
[annotations addObject:annotation];
[annotation release];
}
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Building KD-Tree…");
[self.mapView setAnnotations:annotations];
});
});
[annotations release];
}
所以我看到我有两个ViewControllers,它们保存种子文件这个是
#import "CDStreetlightsMapViewController.h"
@implementation CDStreetlightsMapViewController
- (NSString *)pictoName {
return @"CDStreetlight.png";
}
- (NSString *)clusterPictoName {
return @"CDStreetlightCluster.png";
}
- (NSString *)seedFileName {
return @"CDStreetlights";
}
- (NSString *)seedFileName1 {
return @"CDToilets";
}
@end
另一个是
#import "CDToiletsMapViewController.h"
@implementation CDToiletsMapViewController
- (NSString *)seedFileName {
return @"CDToilets";
}
- (NSString *)pictoName {
return @"CDToilet.png";
}
- (NSString *)clusterPictoName {
return @"CDToiletCluster.png";
}
@end
json文件名为CDToilets和CDStreetlights。。。但我有一个标签栏,里面有厕所和街灯。但假设我想在厕所视图上显示控制路灯和厕所?这是我的问题。。我试过这个
- (void)viewDidLoad {
[super viewDidLoad];
NSMutableArray * annotations = [[NSMutableArray alloc] init];
self.mapView.visibleMapRect = MKMapRectMake(135888858.533591, 92250098.902419, 190858.927912, 145995.678292);
NSLog(@"Loading data…");
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSData * JSONData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:self.seedFileName ofType:@"json"]];
for (NSDictionary * annotationDictionary in [NSJSONSerialization JSONObjectWithData:JSONData options:kNilOptions error:NULL])
{
ADClusterableAnnotation * annotation = [[ADClusterableAnnotation alloc] initWithDictionary:annotationDictionary];
[annotations addObject:annotation];
[annotation release];
}
NSData * JSONData1 = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:self.seedFileName1 ofType:@"json"]];
for (NSDictionary * annotationDictionary in [NSJSONSerialization JSONObjectWithData:JSONData1 options:kNilOptions error:NULL])
{
ADClusterableAnnotation * annotation = [[ADClusterableAnnotation alloc] initWithDictionary:annotationDictionary];
[annotations addObject:annotation];
[annotation release];
}
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Building KD-Tree…");
[self.mapView setAnnotations:annotations];
});
});
[annotations release];
}
我在CDStreetlightsMapViewController
中将seedfile
重命名为seedfile1
,这样我就可以在viewDidLoad
中使用它两次,它没有显示错误,但在模拟器上运行不好,我得到了一个异常:
ClusterDemo[11014:c07]Loading data…
ClusterDemo[11014:1303]***Assertion failure in -[CDToiletsMapViewController seedFileName1], ADClusterMapView-master-7/ClusterDemo/Classes/CDMapViewController.m:86 2013-11-25 23:59:37.524
ClusterDemo[11014:1303]***Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'This abstract method must be overridden!' *** First throw call stack: (0x18b2012 0x1277e7e 0x18b1e78 0xd0df35 0x3fad 0x36cb 0x2deb53f 0x2dfd014 0x2dee2e8 0x2dee450 0x99843e72 0x9982bdaa) libc++abi.dylib: terminate called throwing an exception (lldb)
你可以在这里下载完整的应用程序。。。https://github.com/applidium/ADClusterMapView
如果您阅读了异常,很明显您使用的是一个包含断言的抽象方法,以确保您知道自己犯了错误。您需要在CDToiletsMapViewController
中实现seedFileName1
方法(就像您在CDStreetlightsMapViewController
中所做的那样)。
根据代码,我想你需要添加:
- (NSString *)seedFileName1 {
return @"CDStreetlights";
}