我有一个大约有5行的表格视图,一个存储纬度的数组和另一个存储经度的数组
现在,如果我选择第二行,则应调用两个数组中的2个对象并在地图上显示
有没有办法做到这一点?
或者我是否必须手动输入没有数组的坐标?
答案 0 :(得分:1)
实现UITableViewDelegate' didSelectRowAtIndexPath:
,当它被调用时,从数组中获取经度和经度,并为地图添加注释。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat latitude = latitudes[indexPath.row];
CGFloat longitude = longitudes[indexPath.row];
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);
MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
point.coordinate = coordinate;
point.title = @"Title";
[self.mapView addAnnotation:point];
}