2014-07-01 45 views
0

我有一張桌子並按下一個單元格我想查看相關的針腳,我該如何做到這一點?MKMapView selectAnnotation方法

我有這樣的代碼:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

[_mapView selectAnnotation:[_mapView.annotations objectAtIndex:indexPath.row] animated:true]; 

} 

的問題是,它打開不相關的另一個腳,我能做些什麼?

+0

那麼問題可能是用'_mapView.annotations'陣列或者用'indexPath.row OR indexPath.section' –

+0

不能保證地圖視圖的'annotations'排列的順序保證。見http://stackoverflow.com/questions/9539802/mkmapview-annotations-changing-losing-order和http://stackoverflow.com/questions/13017305/how-to-reorder-mkmapview-annotations-array。 – Anna

+0

您的表格視圖必須使用某些數據源。在該數據源中,您可以保留對相關注釋對象的引用(或者您的數據源對象可能是註釋)。 – Anna

回答

0
int valor =0; 

for (MKPointAnnotation *annotation in _mapView.annotations){ 

    if ([_propLabel.text isEqual:annotation.subtitle]) {  
    [_mapView selectAnnotation:[_mapView.annotations objectAtIndex:valor] animated:true]; 

    } 

    valor++; 
}