【发布时间】:2014-12-28 06:03:07
【问题描述】:
我有两种观点。一个是地图视图,另一个是MKAnnotations 的所有标题的表格视图。现在我可以通过MKAnnotation 的点击在表格视图上调用一个方法。 但我还想做的是通过点击表格视图上的对象调用一个方法,该方法充当MKAnnotation 上的点击。请帮忙?
这是MKAnnotation 点击用于在表格视图上选择对象的表格视图代码。
- (void)highlightCellForPost:(PAWPost *)post {
// Find the cell matching this object.
NSUInteger index = 0;
for (PFObject *object in [self objects]) {
PAWPost *postFromObject = [[PAWPost alloc] initWithPFObject:object];
if ([post isEqual:postFromObject]) {
// We found the object, scroll to the cell position where this object is.
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:PAWWallPostsTableViewMainSection];
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
return;
}
index++;
}
这是调用上述方法的MKAnnotation 的代码。
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
id<MKAnnotation> annotation = [view annotation];
if ([annotation isKindOfClass:[PAWPost class]]) {
PAWPost *post = [view annotation];
[self.wallPostsTableViewController highlightCellForPost:post];
} else if ([annotation isKindOfClass:[MKUserLocation class]]) {
// Center the map on the user's current location:
CLLocationAccuracy filterDistance = [[NSUserDefaults standardUserDefaults] doubleForKey:PAWUserDefaultsFilterDistanceKey];
MKCoordinateRegion newRegion = MKCoordinateRegionMakeWithDistance(self.currentLocation.coordinate,
filterDistance * 2.0f,
filterDistance * 2.0f);
[self.mapView setRegion:newRegion animated:YES];
self.mapPannedSinceLocationUpdate = NO;
}
}
所以我基本上想做我上面所做的事情,但顺序相反。
【问题讨论】:
-
只需在您的
didSelectRowAtIndexPath中调用[mapView selectAnnotation:post] -
我无法从我的 tableView 中调用 mapView,因为它们位于不同的 mapview 中,并且位于 tableView 是其子视图的 viewController 中。有什么办法可以解决吗?
标签: ios objective-c dictionary annotations mapkit