calloutaccessorycontroltapped 或 prepareForSegue [英] calloutaccessorycontroltapped or prepareForSegue

查看:23
本文介绍了calloutaccessorycontroltapped 或 prepareForSegue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张地图,地图上有注释,我可以在表格视图中将这些注释视为单元格,然后我可以查看我选择的任何单元格的详细信息,例如 xcode 中的主详细信息项目

i have a map and the map have annotation , and i can see these annotation in table view as a cells then i can see the details for any cell i selected like the master details project in the xcode

喜欢这个

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
Object *object = [self.objects objectAtIndex:indexPath.row];
DetailsViewController *detailsViewController = segue.destinationViewController;
detailsViewController.detailItem = object;
}

代码用于表格视图中将推送到详细信息视图的单元格

the code was for the cell in the table view that will push to the details view

但我希望用户在注释中按下 UIButtonTypeDetailDisclosure 时,按钮将转到单元格将在表格视图中转到的相同 DetailsViewController

but i want the user when he press UIButtonTypeDetailDisclosure in the annotation then the Button will go to the same DetailsViewController that the cell will go to in the table view

可以这样做吗?

我已阅读有关 calloutAccessoryControlTapped 的信息,但我不确定如何将已被选为我在 DetailsViewController 中声明的 detailItem 的注释制作

i have read about calloutAccessoryControlTapped but i'm not sure how to make the annotation that have been selected to be the detailItem that i have declared in the DetailsViewController

谢谢:)

推荐答案

有点不清楚你在问什么.以下是一些猜测及其答案:

It's a little unclear what you're asking. Here's a couple of guesses and their answers:

从 IB 中的控件(表格单元格、按钮等)拖动是制作转场的好方法,因为 UIKit 可以为您处理一切——当点击控件时,它会自动执行转场.但是有些控件您无法从中创建转场,并且有时您可能希望对执行转场进行编程控制.为此,您可以通过在 IB 中从视图控制器本身中拖来创建一个 segue;给 segue 一个唯一的标识符,然后你可以在你的视图控制器中调用 [self performSegueWithIdentifier:@"myIdentifier"] 只要你想要 segue 发生.

Dragging from controls (table cells, buttons, etc) in IB is a nice way to make segues since UIKit can handle everything for you -- when the control is tapped, it performs the segue automagically. But there are controls you can't create segues from, and times when you might otherwise want programmatic control over performing a segue. For that, you create a segue by dragging from the view controller itself in IB; give the segue a unique identifier, and then in your view controller you can call [self performSegueWithIdentifier:@"myIdentifier"] whenever you want the segue to happen.

在这种情况下,您可能会在 mapView:annotationView:calloutAccessoryControlTapped: 中调用它.

In this case, you'd probably call that from within mapView:annotationView:calloutAccessoryControlTapped:.

大概您的模型对象符合 MKAnnotation 协议,并且您正在使用 addAnnotation(s): 将它们添加到地图中.在这种情况下,当您的地图委托(大概是您的视图控制器)的 mapView:annotationView:calloutAccessoryControlTapped: 方法被调用时,第二个参数将引用相应的 MKAnnotationView.该类有一个属性 annotation,它将指向您的模型对象.

Presumably your model objects conform to the MKAnnotation protocol and you're adding them to the map with addAnnotation(s):. In that case, when your map delegate's (presumably your view controller's) mapView:annotationView:calloutAccessoryControlTapped: method is called, the second parameter has a reference to the corresponding MKAnnotationView. That class has a property annotation which will point back to your model object.

当然,在这个方法中你只是调用了performSegueWithIdentifier:,所以你还不能访问目标视图控制器.因此,您现在需要保留该模型对象引用(例如,在 ivar 中),然后您的 prepareForSegue:sender: 实现可以将其传递给目标视图控制器.

Of course, in this method you're just calling performSegueWithIdentifier:, so you don't yet have access to the destination view controller. So you'll need to hold onto that model object reference (say, in an ivar) for now, and then your prepareForSegue:sender: implementation can pass it to the destination view controller.

这篇关于calloutaccessorycontroltapped 或 prepareForSegue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆