calloutaccessorycontroltapped或prepareForSegue [英] calloutaccessorycontroltapped or prepareForSegue

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

问题描述

我有一个地图,地图上有标注,我可以看到在表视图这些注解为细胞,然后我可以看到的细节,我选择像在x code中的主项目详情<任意单元格/ p>

像这样

   - (无效)prepareForSegue:(UIStoryboardSegue *)赛格瑞发件人:(ID)发送者
{
如果([SEGUE符] isEqualToString:@showDetail]){
NSIndexPath * indexPath = [self.tableView indexPathForSelectedRow]
对象*对象= [self.objects objectAtIndex:indexPath.row];
DetailsViewController * detailsViewController = segue.destinationViewController;
detailsViewController.detailItem =对象;
}

在code是在表视图中的单元格,将推到详细信息视图

但我希望用户,当他在$注释p $ PSS UIButtonTypeDetailDisclosure,则该按钮会转到同一DetailsViewController该单元格将转到表视图

是有可能做到这一点?

我看了一下calloutAccessoryControlTapped,但我不知道如何使已被选定为我在DetailsViewController

宣布了detailItem注释

感谢您:)


解决方案

这是一个有点不清楚你在问什么。这里有一对夫妇的猜测和他们的答案:

如何从地图标注附件按钮进行SEGUE?

从IB控制(表单元格,按钮等)拖动是一个很好的方法,使塞格斯以来的UIKit可以为你搞​​定一切 - 当控制被窃听,它自动地执行SEGUE。但有些时候,否则你可能想在执行SEGUE编程控制控制你无法从塞格斯,和时间。对于这一点,通过从视图控制器本身IB 的拖动的创建SEGUE;给SEGUE一个唯一的标识符,然后在您的视图控制器就可以调用 [自performSegueWithIdentifier:@myIdentifier。每当你想要的SEGUE发生

在这种情况下,你可能会调用从内部图形页面:annotationView:calloutAccessoryControlTapped:

如何通过我的模型对象到下一个视图控制器在这种赛格瑞的?

presumably模型对象符合 MKAnnotation 协议,你将它们添加到地图 addAnnotation(S):。在这种情况下,当你的地图代表的(presumably您的视图控制器)图形页面:annotationView:calloutAccessoryControlTapped:方法被调用时,第二个参数有相应的参考 MKAnnotationView 。这个类有一个属性注释这将指向回到你的模型对象。

当然,在这个方法中你只是打电话 performSegueWithIdentifier:,所以你还没有进入到目标视图控制器。所以你需要守住这个模型对象引用(例如,在伊娃)现在,然后你的 prepareForSegue:发件人:的实施可以将它传递给目标视图控制器。

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 : )

解决方案

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.

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

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