calloutaccessorycontroltapped or prepareForSegue

删除回忆录丶 提交于 2019-12-25 02:19:51

问题


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

like this

    - (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

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

is it possible to do this ?

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

Thank you : )


回答1:


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

How do I perform a segue from a map callout accessory button?

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.

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

How do I pass my model object to the next view controller in this kind of segue?

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.

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.



来源:https://stackoverflow.com/questions/10779628/calloutaccessorycontroltapped-or-prepareforsegue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!