以编程方式执行 Segue 并将参数传递给目标视图 [英] Perform Segue programmatically and pass parameters to the destination view

查看:25
本文介绍了以编程方式执行 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.

你有什么想法吗?

谢谢,亚萨

更新:

我很抱歉这个问题!!!我只是发现,即使以编程方式调用 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屋!

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