Using the showUserLocation property of MKMapView
I have an app at the moment which shows various pins on a map. I've tried setting mapView.showsUserLocation = YES;
to show the user's current pos, however this crashed my app ("Program received signal: SIGABRT") with the follow开发者_开发百科ing error message:
Mon Oct 19 12:31:27 unknown Hull Ads[3111] <Error>: *** -[MKUserLocation counter]: unrecognized selector sent to instance 0x10ad60
Mon Oct 19 12:31:27 unknown Hull Ads[3111] <Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[MKUserLocation counter]: unrecognized selector sent to instance 0x10ad60'
Mon Oct 19 12:31:27 unknown Hull Ads[3111] <Error>: Stack: (...)
This is a little confusing as I haven't used MKUserLocation, or is that the problem?
The app does make use of CoreLocation for other non-related purposes however the app responds in the same way when CoreLocation isn't being used already.
If anyone could help that would be awesome!
Thanks - James
Be sure to include the following in this method:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
if ([annotation class] == MKUserLocation.class) {
return nil;
}
...
}
I do hope you've already fixed this by now ;)
Thanks Berend for answering the question and james.ingham for asking it! I've been looking for a fix for this problem for months and this thread fixed it for me!
Checking for the MKUserLocation pin type would be the most logical thing to do. But who remembers to do that when implementing viewForAnnotation method.. Even if you are not going to use MKuserlocation in your app it would be safe practice to always do this check to avoid running into problems in the future.
精彩评论