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

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

Here I have 2 views:

  • WallViewController
  • TableViewController

WallViewController contains MKMapView, and <

2条回答
  •  天涯浪人
    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  
    // 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.

提交回复
热议问题