如何将数据传递到Xcode的另一个故事板上?

问题描述 投票:0回答:2

在iPhone应用程序中,如何将数据从一个视图(xib文件)传递到另一个故事板?

例如,

我有“ welcome.xib”,其中包含nameTextfield和nextButton,用户将其名称输入nameTextfield并单击next]

该应用程序将导航至“ main.storyboard”,并在“ main.storyboard”中的userNameLabel上显示nameTextfield.text中的文本。

到目前为止我所知道的:

  • 我知道如何在视图之间传递数据(从一个xib文件到另一个xib文件)
  • 我知道如何从视图(xib文件)导航到另一个故事板
  • 在iPhone应用程序中,如何将数据从一个视图(xib文件)传递到另一个情节提要?例如,我有“ welcome.xib”,其中包含nameTextfield和nextButton,用户将输入其名称...

iphone ios xcode xcode4.2 uistoryboard
2个回答
2
投票

在要传递信息的ViewController中,重写-prepareForSegue:sender:方法。

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    DetailViewController *sc = [segue destinationViewController];
    // Here you can set variables in detailViewController. For example if you had a NSString called name
    sc.name = @"name_here";
    // Or you could do
    [sc setName:@"name_here"];
}

0
投票

Swift 4.2 +

© www.soinside.com 2019 - 2024. All rights reserved.