0
Я связываю аннотацию с UITapGestureRecognizer. Я хочу обнаружить прикосновение.Как получить ссылку на аннотацию через отправителя?
if ([annotation isKindOfClass:[Annotation class]])
{
NSString * annotationIdentifier = @"UserAnnotationIdentifier";
CustomAnnotationView * customAnnotationView = (CustomAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
if (!customAnnotationView)
{
customAnnotationView = [[CustomAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:annotationIdentifier];
UITapGestureRecognizer *tapGesture =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(calloutTapped:)];
[customAnnotationView addGestureRecognizer:tapGesture];
Я использую дно кода, но это вызвало ошибку компиляции
-(void) calloutTapped:(id) sender {
id<MKAnnotation> annotation = ((MKAnnotationView*)sender.view).annotation;
ОШИБКА: вид недвижимости не найден на объект типа __strong ид
спасибо, вы делаете мой день! Я принимаю ответ немного позже – user3300062
Как я могу отправить отправителя в UITapGestureRecognizer? отправитель = (UITapGestureRecognizer *) отправитель; не работает – user3300062
Я обновил свой ответ с помощью кастинга по каждому элементу. Правильно устанавливать свойства тега ваших представлений аннотаций, чтобы вы могли идентифицировать их и повторно использовать этот метод для множественных жестов. просто мысль. – graver