gpt4 book ai didi

iphone - 检测选定的 map 注释 Xcode

转载 作者:行者123 更新时间:2023-11-29 04:25:40 26 4
gpt4 key购买 nike

我有一张 map ,并且有多个注释。当我选择注释并点击公开按钮时,会出现一个包含 TableView 的新 View (DetailViewController)。我想要的是,当 DetailViewController 打开时,直接选择所选注释的描述。

this is the map and the annotations, when i tab the appeared the disclosure button image 2 appears and i want the description of the selected annotation become selected

enter image description here

最佳答案

您可以使用以下代码来检测何时在 MKMapView 中选择 MKAnnotation

@interface ClassVC ()
{
int notationTag;
}

- (void)viewDidLoad
{
notationTag = 0; //initialisation of variable
}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
// If it's the user location, just return nil.
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;

// Handle any custom annotations.
if ([annotation isKindOfClass:[MKPointAnnotation class]])
{
// Try to dequeue an existing pin view first.
MKAnnotationView *pinView = (MKAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"CustomPinAnnotationView"];
if (!pinView)
{
// If an existing pin view was not available, create one.
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomPinAnnotationView"];
pinView.canShowCallout = YES;
pinView.image = [UIImage imageNamed:@"mallicon.png"];
pinView.calloutOffset = CGPointMake(0, 32);
//pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinView.tag = notationTag;
} else {
pinView.annotation = annotation;
}
notationTag++;
return pinView;
}
return nil;
}

然后在calloutAccessoryControlTapped.,

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control 
{
ContactDetails *contact=[[ContactDetails alloc] initWithNibName:@"ContactDetails" bundle:nil];
contact.name1Str = [NSString stringWithFormat:@"%d",view.tag];
}

在下一个 View 中添加这行代码

NSIndexPath *index =[NSIndexPath indexPathWithIndex:[name1Str intValue]];
[tableView selectRowAtIndexPath:index animated:NO scrollPosition:UITableViewScrollPositionMiddle];

就我而言,我使用下面的代码重新加载,您也可以尝试

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
self.mapView.centerCoordinate = view.annotation.coordinate;
NSLog(@"======Tag====%ld", (long)view.tag);
NSIndexPath* rowToReload = [NSIndexPath indexPathForRow:[view tag] inSection:0];
[self.collectionView scrollToItemAtIndexPath:rowToReload atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
}

关于iphone - 检测选定的 map 注释 Xcode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12369328/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com