我需要在触摸tableview的任何单元格时向地图视图添加注释。我有一个方法,我添加注释viewForAnnotation和方法didSelectRowAtIndexPath。
我无法建立逻辑连接,在哪里调用方法以及如何调用?
你能帮我吗?
viewForAnnotation方法
- (MKAnnotationView *)mapView:(MKMapView *)mapView2 viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
{
return nil;
}
else if ([annotation isKindOfClass:[CustomAnnotation class]])
{
static NSString * const identifier = @"MyCustomAnnotation";
MKAnnotationView* annotationView = [mapView2 dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView)
{
annotationView.annotation = annotation;
}
else
{
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:identifier];
}
UIImageView * ecz = [[UIImageView alloc]init];
ecz.frame = CGRectMake(0, 0, 65, 49);
ecz.image = [UIImage imageNamed:@"indicator.png"];
UIImageView * vstd = [[UIImageView alloc]init];
vstd.frame = CGRectMake(33, 10, 24, 22);
vstd.image = [UIImage imageNamed:@"indicator_ziyaret_gri"];
UIImageView * nbox = [[UIImageView alloc]init];
nbox.frame = CGRectMake(48, -6, 22, 22);
nbox.image = [UIImage imageNamed:@"numara_kutusu"];
[annotationView addSubview:ecz];
[annotationView addSubview:vstd];
UILabel *index = [[UILabel alloc] initWithFrame:CGRectMake(5,4,15,15)];
index.text = @"1";
index.textColor = [UIColor whiteColor];
[index setFont:[UIFont fontWithName:@"Arial-BoldMT" size:18]];
[nbox addSubview:index];
[index setBackgroundColor:[UIColor clearColor]];
[annotationView addSubview:nbox];
annotationView.canShowCallout = YES;
return annotationView;
}
return nil;
}
didSelectRowAtIndexPath方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
EczaneCell *cell = [tableView cellForRowAtIndexPath:indexPath];
}
答案 0 :(得分:2)
mapView: viewForAnnotation:
方法是MapView的delegate
方法,当您ADD
或REMOVE
来自mapview的任何注释时,MapView内部会调用此方法。
要在TableView
点击添加注释,您应该在tableView:didSelectRowAtIndexPath:
[self.map addAnnotaion:<YOUR Annotation>];