ios - 在没有 segues 的 View Controller 之间传递数据

标签 ios uiviewcontroller

我正在使用 Storyboard,我有一个加载动态按钮的 View 。单击此按钮时,我需要加载第二个 View Controller 并传递数据。我不能使用 segue 作为它的动态按钮。

我使用下面的代码加载第二个 View Controller

UIStoryboard*  sb1 = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone"
                                                           bundle:nil];
UIViewController* vc1 = [sb1 instantiateViewControllerWithIdentifier:@"SecondViewController"];


[self.navigationController pushViewController:vc1 animated:YES];

在第二个 View Controller 中,我需要从第一个 View Controller 访问大约 5 个字段。如何传递数据?

最佳答案

您可以通过按住 ctrl 键并从第一个 Controller 拖动到第二个 Controller 来创建一个不绑定(bind)到按钮的 Segue(不要忘记提供此 segue 和标识符)。

Next 在按钮的 IBAction 中(通过 Interface Builder 或通过 addTarget:self action:forControlEvents: 设置),您可以调用 [self performSegueWithIdentifier:@"YourSegueIdentifier"sender:button ];

您可以像往常一样将数据传递给第二个 Controller ,在 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

关于ios - 在没有 segues 的 View Controller 之间传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15270085/

相关文章:

swift - 使用webview后如何使用segue?

ios - 当 uitableview 嵌入到 uiviewcontroller 中时,为什么 uitableview 的某个部分的标题异常高?

ios - 如何从 appDelegate 到 viewController

ios - 关闭模态视图 Controller 然后执行 segue

ios - 为 UINavigationItem 的 titleView 设置 View Controller

ios - 添加 APP 组所需的通知小部件

iphone - 激活手电筒应用程序的 LED

iphone - [CFNumber 发布] : message sent to deallocated instance

ios - Swift URLSession 在制​​作 PageView 之前无法正常工作

ios - 带删除按钮的叠加 View