0
基本上我使用包含地方对象数组的模型数组。对于每个地点对象,我都有各种属性,例如经度,纬度,地点名称,地点说明等。将链接注释到模型数组
我可以将注释放在地点所在的位置。但是,当用户点击正确的呼叫泄露按钮,我希望他们继续到另一个视图控制器。现在我知道如何做到这一点。
我遇到的严重问题是我无法将点击的注释与我的模型数组关联。在我的下一个视图控制器中,我将显示所有地点信息,但我无法发现哪个注释已被点击。
想想一个索引path.row的tableview,我需要类似的东西来发现正确的注释。
谢谢。
-(void)setMapAnnotations
{
//Create the region - N.B - part of the map you wish to show
MKCoordinateRegion dealMapRegion;
//Center - N.B - The exact center of the region.
CLLocationCoordinate2D center;
center.latitude = 51.481623;
center.longitude = -0.18519;
//Span
MKCoordinateSpan span;
span.latitudeDelta = THE_SPAN;
span.longitudeDelta = THE_SPAN;
dealMapRegion.center = center;
dealMapRegion.span = span;
[self.dealMapMapView setRegion:dealMapRegion animated:YES];
//array to hold places
NSMutableArray *placeLocations = [[NSMutableArray alloc]init];
CLLocationCoordinate2D location;
//After region has been set you need to populate the annotations
for (DealListModel *dealLstObj in self.dealMapModelArray) {
//Get the place from the model objects stored in the model array
PlaceDealAnnotation *placeAnnontation = [[PlaceDealAnnotation alloc]init];
double tempPlaceLatitude = [dealLstObj.placeLatitude doubleValue];
double tempPlaceLongitude = [dealLstObj.placeLongitude doubleValue];
location.latitude = tempPlaceLatitude;
location.longitude = tempPlaceLongitude;
placeAnnontation.coordinate = location;
placeAnnontation.title = dealLstObj.placeDescription;
//adding array of locations map
[placeLocations addObject:placeAnnontation];
}
[self.dealMapMapView addAnnotations:placeLocations];
}//end of setMapAnnotations
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
NSString *annotationIdentifier = @"CustomViewAnnontation";
DealMapCustomAnnotationView *customAnnotationView = (DealMapCustomAnnotationView *) [self.dealMapMapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
if (!customAnnotationView) {
customAnnotationView = [[DealMapCustomAnnotationView alloc]initWithAnnotationwithImage:annotation reuseIdentifier:annotationIdentifier annotationViewImage:[UIImage imageNamed:@"pin.png"]];
customAnnotationView.canShowCallout = YES;
customAnnotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
}
return customAnnotationView;
}
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
[self performSegueWithIdentifier:@"mapPlaceSegue" sender:view];
}
令人惊叹!完美工作。这非常有帮助。我没有在MKAnnotation上寻找标签属性,但没有提供任何内容。我没有想到创造我自己的。毫无疑问,这个解决方案将对未来的这个和其他事物有用!谢谢 – Anthony