以编程方式执行Segue并将参数传递到目标视图 [英] Perform Segue programmatically and pass parameters to the destination view
问题描述
在我的应用程序中我有一个以编程方式执行segue的按钮:
in my app I've a button that performs a segue programmatically:
- (void)myButtonMethod
{
//execute segue programmatically
[self performSegueWithIdentifier: @"MySegue" sender: self];
}
我想知道是否有办法引用目的地视图和传递一些参数。
I would like to know if there is a way to reference the destination view and to pass it some parameters.
我知道在 prepareForSegue
方法中,我可以用以下方式引用它: myDestinationViewController * vc = [segue destinationViewController];
,但我不知道如何以编程方式执行segue。
I know that in prepareForSegue
method, I can refer to it with:myDestinationViewController *vc = [segue destinationViewController];
, but I don't know how to this executing the segue programmatically.
您有什么想法吗?
谢谢,yassa
更新:
对不起这个问题!!!我只是发现,即使以编程方式调用segue,也会调用 prepareForSegue
方法,因此可以以相同的方式传递参数。
I'm sorry for this question!!! I simply discovered that, even if the segue is invoked programmatically, the prepareForSegue
method is called anyway and so it is possible to pass parameters in the same usual way.
推荐答案
答案很简单就是如何触发segue没什么区别。
The answer is simply that it makes no difference how the segue is triggered.
在任何情况下都会调用 prepareForSegue:sender:
方法,这是您传递参数的地方。
The prepareForSegue:sender:
method is called in any case and this is where you pass your parameters across.
这篇关于以编程方式执行Segue并将参数传递到目标视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!