iphone – 单击DetailDesclosure按钮时,MKAnnotationView按下以
发布时间:2020-12-14 20:00:51 所属栏目:百科 来源:网络整理
导读:我想在我正在显示的地图上单击DetailDisclosure时切换视图.我目前的代码如下: - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{ DetailViewController *detailViewCont
我想在我正在显示的地图上单击DetailDisclosure时切换视图.我目前的代码如下:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil]; detailViewController.title = dictionary[@"placeLatitude"] [self.navigationController pushViewController:detailViewController animated:YES]; } 我可以用这个推送到视图控制器,但我还没想出如何强制它从用于生成地图的JSON数组中拉出细节.我正在拉这样的数据来生成地图: for (NSDictionary *dictionary in array) { // retrieve latitude and longitude from the dictionary entry location.latitude = [dictionary[@"placeLatitude"] doubleValue]; location.longitude = [dictionary[@"placeLongitude"] doubleValue]; //CAN I LOAD THE TITLE/ID OF THE LOCATION HERE? 我知道我有点偏离目标.也许只是向正确的方向踢一脚可能有所帮助.谢谢! 解决方法
如果您正在使用故事板并且从当前场景到目标场景有一个segue,则可以只响应calloutAccessoryControlTapped.例如:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { [self performSegueWithIdentifier:@"Details" sender:view]; } 显然,如果您要为不同的注释类型调用不同的segue,则可以检查与该视图关联的注释类型等. 当然,如果你想像往常一样将任何信息传递给prepareForSegue中的下一个场景. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"Details"]) { MKAnnotationView *annotationView = sender; [segue.destinationViewController setAnnotation:annotationView.annotation]; } } 如您所见,我将注释对象传递给下一个视图.如果JSON结构中有与每个注释关联的其他字段,则一个简单的解决方案是将属性添加到与要跟踪的每个字段关联的自定义视图中.只需转到.h作为注释自定义类并添加所需的属性.然后,当您创建自定义注释(要添加到地图)时,也可以设置这些属性.然后,当您将此注释传递给下一个视图控制器时,所有所需的属性都将在那里可用. 显然,如果您正在使用NIB,只需执行任何您想要的NIB等效实例化下一个视图控制器,设置您想要的任何属性,并推送到它或以模态方式呈现它,例如: - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { DetailsViewController *controller = [[DetailsViewController alloc] initWithNibName:nil bundle:nil]; controller.annotation = annotationView.annotation; [self.navigationController pushViewController:controller animated:YES]; // or use presentViewController if you're using modals } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |