了解 performSegueWithIdentifier [英] Understanding performSegueWithIdentifier

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

问题描述

有比我更博学的人可以为我解释 performSegueWithIdentifier:sender: 吗?我需要切换视图(和类),并将一些 NSStrings 和 ID 传递给该视图的类.我想知道这是否可以使用 performSegueWithIdentifier:sender:

Can someone more knowledgeable than I explain performSegueWithIdentifier:sender: for me? I need to switch views (and classes) and also carry a few NSStrings and IDs over to that view's class. I was wondering if this is possible with performSegueWithIdentifier:sender:

谢谢!

推荐答案

首先,您必须在故事板中设置转场并为其提供适当的标识符.(点击 segue(左面板),然后点击 Attributes(右面板).

First, you have to have set up the segue in your storyboard and give it the appropriate identifier. (Click on the segue (left panel) and then click on Attributes (right panel).

然后,您可以将其链接到故事板中的按钮或表格行的选择,或者您可以使用 performSegueWithIdentifier:sender: 在代码中调用它.

You can then link this to buttons or selection of table rows from your storyboard, or you can call it in code using performSegueWithIdentifier:sender:.

此后,您的视图控制器将收到 prepareForSegue:sender: 消息.您可以在您的视图控制器子类中重写此方法,并可以按如下方式配置目标视图控制器:

After this, your view controller will be sent the prepareForSegue:sender: message. You override this method in your view controller subclass, and can configure the target view controller as follows:

TargetViewController *targetVC = (TargetViewController*)segue.destinationViewController;
targetVC.string1 = string1;

等等.此方法中的 sender 将是您在原始方法调用中用作 sender 的对象.

And so forth. The sender in this method will be the object that you use as the sender in the original method call.

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

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