当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - Unrecognized selector [MKCircle pointCount] when adding MKCircleOverlay to MKMapView

问题描述:

I am using Objective C to develop an app for iOS 9.0 and later.

The app includes a view controller with a MKMapView object. The view controller is the map view delegate.

I am having problems adding a MKCircle overlay in the implementation of viewWillAppear:animated.

Using the addOverlay:level: method does not resolve the issue.

The implementation looks like:

- (void)viewDidLoad {

[super viewDidLoad];

[self.mapView setDelegate:self];

[self.mapView setZoomEnabled:YES];

[self.mapView setScrollEnabled:YES];

}

- (void)viewWillAppear:(BOOL)animated {

[super viewWillAppear:animated];

self.locationCircle = [MKCircle circleWithCenterCoordinate:self.locationPin.coordinate radius:1000000.0];

[self.mapView addOverlay:self.locationCircle];

}

- (MKOverlayRenderer *)rendererForOverlay:(id<MKOverlay>)overlay {

if ([overlay isKindOfClass:[MKCircle class]]) {

MKCircleRenderer *renderer = [[MKCircleRenderer alloc] initWithCircle:(MKCircle *)overlay];

renderer.fillColor = [[UIColor yellowColor] colorWithAlphaComponent:0.25];

return renderer;

} else {

return [self.superclass rendererForOverlay:overlay];

}

}

Specifically, the app is crashing as soon as the map view attempts to show any part of the circle overlay.

The app is successfully rendering polygon overlays and various pin annotations on the map view. The error message details are:

2016-11-07 12:35:21.643 [MKCircle pointCount]: unrecognized selector sent to instance 0x6000004902c0

2016-11-07 12:35:21.645 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MKCircle pointCount]: unrecognized selector sent to instance 0x6000004902c0'

*** First throw call stack:

(

0 CoreFoundation 0x000000010cdc334b __exceptionPreprocess + 171

1 libobjc.A.dylib 0x000000010c82421e objc_exception_throw + 48

2 CoreFoundation 0x000000010ce32f34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132

3 CoreFoundation 0x000000010cd48c15 ___forwarding___ + 1013

4 CoreFoundation 0x000000010cd48798 _CF_forwarding_prep_0 + 120

5 MapKit 0x0000000109af40a3 CreatePathForPolygon.38297 + 57

6 MapKit 0x0000000109af3e4c -[MKPolygonRenderer createPath] + 128

7 MapKit 0x0000000109aeefda -[MKOverlayPathRenderer drawMapRect:zoomScale:inContext:] + 72

8 MapKit 0x0000000109aefd89 __47-[MKOverlayRenderer overlay:drawKey:inContext:]_block_invoke + 671

9 MapKit 0x0000000109aefdda _worldsForBounds.37697 + 58

10 MapKit 0x0000000109aef99f -[MKOverlayRenderer overlay:drawKey:inContext:] + 224

11 VectorKit 0x00000001170e0534 __40-[VKRasterOverlayTileSource _queueDraw:]_block_invoke + 484

12 libdispatch.dylib 0x000000010de3a980 _dispatch_call_block_and_release + 12

13 libdispatch.dylib 0x000000010de640cd _dispatch_client_callout + 8

14 libdispatch.dylib 0x000000010de43499 _dispatch_queue_override_invoke + 1733

15 libdispatch.dylib 0x000000010de453b7 _dispatch_root_queue_drain + 720

16 libdispatch.dylib 0x000000010de4508b _dispatch_worker_thread3 + 123

17 libsystem_pthread.dylib 0x000000010e20d4de _pthread_wqthread + 1129

18 libsystem_pthread.dylib 0x000000010e20b341 start_wqthread + 13

)

libc++abi.dylib: terminating with uncaught exception of type NSException

Experimenting, I have found that the circle overlay can be added without crashing the app if it is in a part of the map that is not being displayed on the screen. As soon as the user pans across to the part of the map where the circle is, this crash occurs.

The error occurs when using the simulator with both iOS 10.1 and iOS 9.0.

Any thoughts on why this is happening will be greatly appreciated.

网友答案:

Thanks everyone for input. The problem in the end was because of an incorrect method signature:

- (MKOverlayRenderer *)rendererForOverlay:(id<MKOverlay>)overlay

which should have been:

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay

This was not causing wider problems because there was another implementation of the method with the correct signature elsewhere in the code. That method was trying to treat the MKCircle as a MKPolygon and so was triggering the pointCount problem.

分享给朋友:
您可能感兴趣的文章:
随机阅读: