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 following 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 - Джеймс

6
задан ingh.am 7 April 2010 в 22:15
поделиться

2 ответа

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 ;)

24
ответ дан 8 December 2019 в 04:30
поделиться

Спасибо Berend за ответ на вопрос и james.ingham за то, что задал его! Я искал решение этой проблемы в течение нескольких месяцев, и эта тема помогла мне!

Проверка типа пина MKUserLocation была бы наиболее логичной. Но кто помнит, что это нужно делать при реализации метода viewForAnnotation... Даже если вы не собираетесь использовать MKuserlocation в своем приложении, было бы безопасной практикой всегда выполнять эту проверку, чтобы избежать проблем в будущем.

1
ответ дан 8 December 2019 в 04:30
поделиться
Другие вопросы по тегам:

Похожие вопросы: