我正在使用 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/