How to select map pin when tapping table row that associates with it?

前端 未结 2 799
故里飘歌
故里飘歌 2021-01-28 08:15

Here I have 2 views:

  • WallViewController
  • TableViewController

WallViewController contains MKMapView, and <

相关标签:
2条回答
  • 2021-01-28 08:28

    You can use PFObject.objectId to find annotation what you want.

    PFObject *selectedObject = [self.objects objectAtIndex:i];
    
    for (id annotation in wallViewController.mapView.annotations)
    {
        if ([annotation isKindOfClass:[PAWPost class]])
        {
            PAWPost *post = (PAWPost*)annotation;
            if ([post.object.objectId isEqualToString:selectedObject.objectId])
            {
                [wallViewController.mapView selectAnnotation:annotation  animated:YES];
                break;
            }
        }
    }
    
    0 讨论(0)
  • 2021-01-28 08:29

    You can do your annotation as object that support MSAnnotation protocol. So when you select your cell - you'll exactly know what object is behind this action. And in that case you - your annotation will be exactly the object you've selected by tapping on UITableViewCell.

    So - your object PAWPost just should support MKAnnotation protocol:

    @interface PAWPost : NSObject <MKAnnotation> 
    // Interface here
    @end
    
    @implementation PAWPost
    // ...
    - (CLLocationCoordinate2D)coordinate {
        return <#your coordinate here#>;
    }
    // ...
    @end
    

    P.S. You dont need to create new local instance of WallViewController class in didSelectRowAtIndexPath: method. Because at that time your WallViewController will not have MapView. Instead that - create instance of WallViewController before and use pointer to it.

    0 讨论(0)
提交回复
热议问题